如果您发现内容含有错误或公司内部信息,请予以指出,本人不胜感激。。。。
服务器端A项目:
package com.remote;
public interface IRemoteService {
// TODO;测试远程调用方法
public String getString(String str);
}
package com.remote.impl;
public class RemoteServiceImpl implements IRemoteService {
private IMyService myService;
public String getString(String msg) {
String str = "远程服务调用成功........ " + msg;
return str;
}
}
配置remote-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 通过Spring HttpInvoker机制暴露远程访问服务 -->
<bean id="remotingService" class="com.remote.impl.RemoteServiceImpl">
<property name="myService" ref="myService"></property>
</bean>
<bean name="/remoteService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="remotingService" />
<property name="serviceInterface"
value="com.remote.IRemoteService" />
</bean>
</beans>
web.xml中加入
<!-- 载入remote-servlet.xml文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>remote-servlet.xml</param-value>
</context-param>
<!-- 配置DispatcherServlet -->
<servlet>
<servlet-name>remote</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置该Servlet随应用启动时候启动 -->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- 配置DispatcherServlet映射的url -->
<servlet-mapping>
<servlet-name>remote</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>