Spring Hessian
1:服务器端pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>2:服务器端web.xml
<!-- spring hessian --> <servlet> <servlet-name>hessian</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/hessian-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>hessian</servlet-name> <url-pattern>/hessian/*</url-pattern> </servlet-mapping>
3:服务器端
(1):applicationContext.xml
<bean id="appService" class="com.fangtoon.appcenter.platform.app.service.AppService" />
(2):hessian-servlet.xml:
<beans>
<bean name="/appServiceCall" class="org.springframework.remoting.caucho.HessianServiceExporter">
<!-- appService是实现了IAppService接口的SpringBean -->
<property name="service" ref="appService"/>
<property name="serviceInterface" value="com.fangtoon.appcenterclient.app.service.IAppService"/>
</bean>
</beans>4:客户端spring配置文件:
<!-- Hessian远程调用配置 -->
<bean id="appService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="${hessianBaseUrl}/hessian/appServiceCall"/>
<property name="overloadEnabled" value="true" />
<property name="serviceInterface" value="com.fangtoon.appcenterclient.app.service.IAppService"/>
</bean>5:使用Spring调用:
@Resource(name="appService") IAppService appService;
6:普通Java调用:
import java.util.List;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.caucho.hessian.client.HessianProxyFactory;
import com.fangtoon.appcenterclient.app.service.IAppService;
import com.fangtoon.appcenterclient.dto.app.BizApp;
public class HessianTest {
private Logger logger = LoggerFactory.getLogger(getClass());
@Test
public void testHessianJavaCall() {
try {
String url = "http://localhost:8082/AppCenter/hessian/appServiceCall";
HessianProxyFactory factory = new HessianProxyFactory();
IAppService appService = (IAppService) factory.create(IAppService.class, url);
List<BizApp> ret = appService.find();
System.out.println(ret.get(0).getName());
} catch (Exception e) {
logger.error("", e);
}
}
}7:注意:
(1):传输的Dto必须实现可序列化接口.
相关推荐
yupi0 2020-10-10
spring 2020-08-18
编程点滴 2020-07-29
幸运小侯子 2020-07-05
itjavashuai 2020-07-04
qingjiuquan 2020-06-29
shushan 2020-06-25
小鱿鱼 2020-06-22
咻pur慢 2020-06-18
melonjj 2020-06-17
qingjiuquan 2020-06-13
neweastsun 2020-06-05
小鱿鱼 2020-06-05
mxcsdn 2020-05-31
吾日五省我身 2020-05-27
牧场SZShepherd 2020-05-27
sweetgirl0 2020-05-14