最近项目里使用了大致看了下流程。
1.添加jar包,这里就不在赘述了。
服务器端
2.创建service(服务器客户端共用)
public interface IRemoteService {
public String remote(String value);
}
3.创建实现类
public class RemoteServiceImpl implements IRemoteService {
@Override
public String remote(String value) {
return "This is from remote service" + value;
}
}
4.web.xml
<servlet>
<servlet-name>dispatcherservlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:xxxxxx.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherservlet-name>
<url-pattern>/remote/*</url-pattern>
</servlet-mapping>
5.配置文件(暴漏远程服务)
<bean id="remoteService" class="xxx.RemoteServiceImpl" />
<bean name="/remoteService"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="remoteService" />
<property name="serviceInterface" value="xxx.xxx.xxx.IRemoteService" />
</bean>
客户端
1.配置文件(获取远程服务)
<bean id="remoteServiceClient" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="IP地址+端口号/remote/remoteService" />
<property name="serviceInterface" value="xxx.xxx.xxx.IRemoteService" />
</bean>
2.使用
ApplicationContext context = new ClassPathXmlApplicationContext("xxx.xml");
IHessianService service = (IHessianService) context.getBean("hessionServiceClient");
System.out.println(service.getString());
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于