Remoting in spring

Viewed 114

I am facing a problem with Spring RMI I want to use RMI to connect my three-tier system. I have DOA packages in the first tier, in the second tier there are services and controller for consuming a web service I want to connect the first tier with the second using RMI and I am facing problems with auto wiring the server to my RMI client.

@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

@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;   
    }

Client

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

@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.

please any help can be great

0 Answers
Related