我遇到了Spring RMI的问题 我想使用RMI连接我的三层系统。 我在第一层有DOA软件包,在第二层中有用于使用Web服务的服务和控制器 我想使用RMI连接第一层和第二层,并且在将服务器自动连接到RMI客户端时遇到问题。
@SpringBootApplication
@ComponentScan("sep.via.dk.sep3JPA")
public class Sep3JpaApplication {
@Bean
public RemoteServer createBarServiceLink() {
RmiProxyFactoryBean rmiProxyFactoryBean= new RmiProxyFactoryBean();
rmiProxyFactoryBean.setServiceUrl("rmi://localhost:1099/helloworldrmi");
rmiProxyFactoryBean.setServiceInterface(RemoteServer.class);
rmiProxyFactoryBean.afterPropertiesSet();
System.out.println("client is running");
return (RemoteServer) rmiProxyFactoryBean.getObject();
}
public static void main(String[] args) throws AccessException, RemoteException, NotBoundException {
RemoteServer helloWorldRMI= SpringApplication.run(Sep3JpaApplication.class, args).getBean(RemoteServer.class);
RmiClient client = new RmiClient(helloWorldRMI);
System.out.println("================Client Side ========================");
System.out.println(helloWorldRMI.sayHelloRmi("FADI"));
}
配置
@Configuration
public class Config {
@Bean
RemoteExporter registerRMIExporter() {
RmiServiceExporter exporter = new RmiServiceExporter();
exporter.setServiceName("helloworldrmi");
exporter.setServiceInterface(RemoteServer.class);
exporter.setService(new RmiServer());
System.out.println("server is running");
return exporter;
}
客户
public class RmiClient {
private RemoteServer server;
public RmiClient(RemoteServer server) throws AccessException, RemoteException, NotBoundException {
this.server=server;
}
public void addCustomer(Customer customer) throws RemoteException {
server.getCustomerDAO().addCustomer(customer);
}
服务
@Service
public class CustomerServiceImplementation implements CustomerService {
@Autowired
public RmiClient rmiClient;
@Autowired
public MyPayment myPayment;
@Override
public boolean addCustomer(Customer customer) throws RemoteException {
boolean checkPayment = checkPayment();
if(checkPayment!=true) {
return false;
}
**************************
APPLICATION FAILED TO START
***************************
Description:
Field rmiClient in sep.via.dk.sep3JPA.service.customerService.CustomerServiceImplementation required a bean of type 'sep.via.dk.sep3JPA.rmiClient.RmiClient' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'sep.via.dk.sep3JPA.rmiClient.RmiClient' in your configuration.
请任何帮助会很棒