java—在spring中导出两个服务

esbemjvw  于 2021-07-15  发布在  Java
关注(0)|答案(0)|浏览(264)

我在spring中遇到了一个问题,当我尝试将两个服务从服务器导出到客户端时,出现了下一个错误:

Caused by: org.springframework.remoting.RemoteLookupFailureException: Could not find RMI service [rmi://localhost:1099/ClientsService] in RMI registry; nested exception is java.rmi.NotBoundException: ClientsService

这是我在服务器端的配置:

@Configuration
public class ClientsServerConfig {
    @Bean
    RmiServiceExporter rmiServiceExporter() {
        RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
        rmiServiceExporter.setServiceInterface(ClientService.class);
        rmiServiceExporter.setService(clientService());
        rmiServiceExporter.setServiceName("ClientsService");
        return rmiServiceExporter;
    }
    @Bean
    ClientService clientService() {
        return new ClientsServiceImpl(clientRepository());
    }
    @Bean
    RepositoryInterface<Long, Client> clientRepository() {
        return new ClientDbRepository();
    }
}

@Configuration
public class GunProviderServerConfig{
    @Bean
    RmiServiceExporter rmiServiceExporter() {
        RmiServiceExporter rmiServiceExporter = new RmiServiceExporter();
        rmiServiceExporter.setServiceInterface(GunProviderService.class);
        rmiServiceExporter.setService(gunProviderService());
        rmiServiceExporter.setServiceName("GunProviderService");
        return rmiServiceExporter;
    }
    @Bean
    GunProviderService gunProviderService() {
        return new GunProviderServiceImpl(gunProviderRepository());
    }
    @Bean
    RepositoryInterface<Long, GunProvider> gunProviderRepository() {
        return new GunProviderDbRepository();
    }
}

这是客户端的配置:

@Configuration
public class ClientConfig {

    @Bean
    RmiProxyFactoryBean rmiProxyFactoryBean() {
        RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
        rmiProxyFactoryBean.setServiceUrl("rmi://localhost:1099/ClientsService");
        rmiProxyFactoryBean.setServiceInterface(ClientService.class);
        return rmiProxyFactoryBean;
    }
    @Bean
    RmiProxyFactoryBean rmiProxyFactoryBean2() {
        RmiProxyFactoryBean rmiProxyFactoryBean = new RmiProxyFactoryBean();
        rmiProxyFactoryBean.setServiceUrl("rmi://localhost:1099/GunProviderService");
        rmiProxyFactoryBean.setServiceInterface(GunProviderService.class);
        return rmiProxyFactoryBean;
    }

我认为这个错误是因为应用程序在导出两个服务时不知道要使用什么服务。如果我注解“gunproviderserverconfig”和“rmiproxyfactorybean2”,这样我就只有clientservice了,应用程序就可以运行了。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题