RMI spring
1. Service interface class and its implementation
/ * define a remote interface * / public interface HelloService {/ * methods that need to be called remotely * @ param msg * @ return * / String sayHello (String msg);}
Public class HelloServiceImpl implements HelloService {public String sayHello (String msg) {return "server received the msg:" + msg;}}
2.RmiServiceExporter (server side)
3.RmiProxyFactoryBean (client)
4. test
Public class HelloServer {public static void main (String [] args) {new ClassPathXmlApplicationContext ("spring-rmi-server.xml"); System.err.println ("rmi service startup!");}} public class HelloClient {public static void main (String [] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext ("spring-rmi-client.xml"); HelloService helloService = (HelloService) applicationContext.getBean ("helloService") System.err.println (helloService.sayHello ("Test!");}}
Note: Registry service registration problems, sometimes there will be service startup error.