spring集成hession及测试调用

spring集成hession使用了好久了,便是框架这种东西搭完也就放哪了,再重新搭一遍的时候之前做过的内容,还要慢慢回忆,在这里记录一下吧。 首先不管是直接复制jar包还是使用maven管理总之包不能少(这个不用多说) 先添加web.xml配置:

        <servlet>
		<servlet-name>hessianServices</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-hessian.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>hessianServices</servlet-name>
		<url-pattern>/hessian/*</url-pattern>
	</servlet-mapping>

设置 拦截servlet,集成hession到spring,引入spring-hession.xml配置文件 spring-hession.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
						http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
						http://www.springframework.org/schema/context
						http://www.springframework.org/schema/context/spring-context-3.0.xsd
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    					http://www.springframework.org/schema/aop 
    					http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
	default-lazy-init="false">

	<bean name="/helloService" class="org.springframework.remoting.caucho.HessianServiceExporter">
		<property name="service" ref="hello" />
		<property name="serviceInterface" value="com.xx.Hello" />
	</bean>
	
</beans>

hello 是配置的spring配置文件(或者注解形式)的bean(是Hello接口的实现方法) com.xx.Hello是要对外提供方法的接口 服务端基本ok了 调用方法:

String url = "http://127.0.0.1:8080/App/hessian/helloService";
		HessianProxyFactory hpf = new HessianProxyFactory();
		
		try {
			Hellomss = (Hello) hpf.create(Hello.class, url);
			int i = mss.find("xxx");
			System.out.println("xxx:"+i);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} 

如果返回值类型为自定义的bean要保证bean实现Serializable接口,定义serialVersionUID属性值

转载于:https://my.oschina.net/iuv/blog/511969

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值