I. Opening Speech
In the previous RMI-Java remote method call blog, the JDK native class is used for remote method call. This article uses the APIS provided by spring to integrate RMI, hoping to help you.
Ii. Core APIs
1. Client: the Core of the client is RmiProxyFactoryBean, which contains two attributes: serviceUrl (Remote Call address) and serviceInterface (Remote Call interface)
2. server: RmiServiceExporter outputs the Bean managed by spring into an RMI service. By packing the Bean in an adapter class, the adapter class is bound to the RMI registry, and proxy the request to the service class.
Iii. Environment preparation
1. Running environment:
Spring2.5, JDK6.0
2. jar package: spring. jar, commons-logging.jar
3. code structure:
4. Code Testing
1. SumService: addition operation interface
public interface SumService {public int getAdd(int a, int b);}
2. SumServiceImpl: addition operation implementation
public class SumServiceimpl implements SumService {public int getAdd(int a, int b) {return a + b;}}
3. Server
public class Server {public static void main(String[] args) {// init spring contextApplicationContext context = new ClassPathXmlApplicationContext("application_context_server.xml");System.out.println("server start!");}}
4. Client
public class Client {private static final Integer NUM_1 = 1;private static final Integer NUM_2 = 2;public static void main(String[] args) {ApplicationContext ctx = new ClassPathXmlApplicationContext("application_context_client.xml");SumService sumService = (SumService) ctx.getBean("rmiProxyFactoryBean", SumService.class);System.out.println("client sum: " + NUM_1 + " + " + NUM_2 + " = " + sumService.getAdd(NUM_1, NUM_2));}}
5. Configure application_context_server.xml on the server
6. Configure application_context_client.xml on the client
7. Source: http://download.csdn.net/detail/zdp072/7423185