Get the App
SLTechnology News&Howtos  ›  Network Security  › 

RMI spring

Shulou Source: shulou.com Published: 2022-06-01 02:46:01 10月04日 Update

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.

Tags: Services tests interfaces business customers clients methods problems Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Linux Shulou Technology NVidia Apple