二、hessian与spring集成
来源:互联网 发布:java web后端 编辑:程序博客网 时间:2024/06/05 07:50
spring提供了与hessian的集成,这样就会大大减少代码的嵌入和编写,让我们让关注与自身的业务,spring的org.springframework.remoting.caucho.HessianServiceExporter类提供了hessian的代理,下面开始hessian于spring的简单集成。
1、准备spring和hessian的相关依赖包
spring的依赖包
hessian依赖包 hessian-4.0.7.jar(可以自行去hessian官网下载)
2、编写服务接口api和实现
api类
api实现
3、编写hessian与spring集成的xml
通过org.springframework.remoting.caucho.HessianServiceExporter代理hessian,我命名为hessian-remote-servlet.xml(注意命名和web.xml中servlet配置有关系,否则找不到xml配置文件)
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="basicService" class="com.jimi.hessian.test.impl.BasicService"/>
<bean name="/helloHessian" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="basicService"/>
<property name="serviceInterface" value="com.jimi.hessian.test.api.Basic"/>
</bean>
</beans>
4、配置web.xml文件,加载hessian-remote-servlet.xml文件
<!-- hessian与servlet集成 -->
<servlet>
<servlet-name>hessian-remote</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hessian-remote</servlet-name>
<url-pattern>/remote/*</url-pattern>
</servlet-mapping>
5、编写与spring集成的hessian客户端
在res下建立remote-client.xml文件
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="clientSpring" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/hessian/remote/helloHessian"/>
<property name="serviceInterface" value="com.jimi.hessian.test.api.Basic"/>
</bean>
</beans>
结构图如下:
6、编写java客户端代码
使用ClassPathXmlApplicationContext加载remote-client.xml文件
public class HessianClient {
final static String url = "http://localhost:8080/hessian/remote/helloHessian";
public static void main(String[] args) throws Exception {
//hessian工程代理
// HessianProxyFactory factory = new HessianProxyFactory();
// Basic basic = (Basic) factory.create(url);
// System.out.println(basic.hello("jimi"));
//spring集成
ApplicationContext context = new ClassPathXmlApplicationContext("remote-client.xml");
//从spring容器中获取hessian代理
Basic basic = (Basic) context.getBean("clientSpring");
System.out.println(basic.hello("good boy"));
}
}
输出结果如下 hello good boy
- 二、hessian与spring集成
- Hessian与Spring集成
- Hessian入门(与Spring集成)
- Hessian入门(与Spring集成)
- Hessian入门(与Spring集成)
- Hessian入门(与Spring集成)
- Hessian入门(与Spring集成)
- Hessian入门(与Spring集成)
- Hessian学习之(二):Hessian集成到Spring
- hessian(二)--与spring整合
- Hessian使用(与Spring的集成)
- Spring集成Hessian
- Spring集成Hessian
- spring hessian 集成开发
- Spring 集成 Hessian
- spring 集成 Hessian
- spring集成Hessian
- Spring集成Hessian
- oracle查看允许的最大连接数和当前连接数等信息
- 地址栏查看浏览器版本信息
- codeblocks +cygwin 开发c++及undefined reference to " "
- LDAP简介及其使用
- object-c 内存管理
- 二、hessian与spring集成
- C# 手动添加响应函数
- nmap参数详解
- 在ListView中嵌套ListView的事件处理
- Android中根据屏幕大小调整bitmap大小
- 从零开始写一个arm下的裸板程序
- PHP快速入门 -- ffmpeg扩展
- 基于DTMF音调的数据通信(二)——android平台
- python中文名称字符串操作的问题