spring与hessian整合例
spring与hessian的简单应用实现例:
开发环境:window7 64,jdk8,tomcat8,spring4.2.5,hessian4.0
开发语言:java
hessianServer端代码:
package org.server.hessian.study.implDef;
public interface Greet {
public String sayHello();
public String sayHelloToUser();
}
package org.server.hessian.study.impl; import org.server.hessian.study.business.User;
import org.server.hessian.study.implDef.Greet; public class Hello implements Greet { private User u; public User getU() {
return u;
} public void setU(User u) {
this.u = u;
} @Override
public String sayHello() {
return "Good morning";
} @Override
public String sayHelloToUser() {
return "Good morning " + u.getName();
} }
package org.server.hessian.study.business; import java.io.Serializable;
import java.util.HashMap;
import java.util.Map; public class User implements Serializable {
private String name = "Dale"; public User() { } public User(String name) {
this.name = name;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public Map getInfo() {
Map m = new HashMap<>();
m.put("name", this.name); return m;
}
}
hessianServer端web.xml配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:appConf/spring-app-beans.xml
</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping> <servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>namespace</param-name>
<param-value>/config/springMapping/**/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping> <servlet>
<servlet-name>callHessianServer</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>callHessianServer</servlet-name>
<url-pattern>/remoting</url-pattern>
</servlet-mapping>
hessianServer端spring-app-beans.xml配置:
<bean id="b_user" class="org.server.hessian.study.business.User"/>
<bean id="hessianServer" class="org.server.hessian.study.impl.Hello">
<property name="u" ref="b_user"/>
</bean>
<bean name="callHessianServer"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<!-- service引用具体的实现实体Bean-->
<property name="serviceInterface"
value="org.server.hessian.study.implDef.Greet"/>
<property name="service" ref="hessianServer"/>
</bean>
hessianClient端代码:
package org.client.hessian.study; import com.caucho.hessian.client.HessianProxyFactory;
import org.server.hessian.study.implDef.Greet; import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map; public class ClientTest {
public static void main(String[] args) {
String remoteUrl = "http://127.0.0.1:8080/hessianServer/remoting";
HessianProxyFactory factory = new HessianProxyFactory();
Greet server = null;
Map m = new HashMap<>();
m.put("name","Tome");
try {
server = (Greet) factory.create(Greet.class, remoteUrl);
print(server);
print(server.sayHelloToUser());
print(server.sayHello());
} catch (MalformedURLException e) {
print(e);
}
} public static void print(Object s) {
System.out.println(s);
} }
使用使用tomcat启动server服务后,
执行client端。
以上内容为个人学习测试用例,
参考资料为:spring文档内容【27.3 Using Hessian or Burlap to remotely call services via HTTP】部分。
spring与hessian整合例的更多相关文章
- Mybatis学习--spring和Mybatis整合
简介 在前面写测试代码的时候,不管是基于原始dao还是Mapper接口开发都有许多的重复代码,将spring和mybatis整合可以减少这个重复代码,通过spring的模板方法模式,将这些重复的代码进 ...
- 九 spring和mybatis整合
1 spring和mybatis整合 1.1 整合思路 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用Sq ...
- Spring与Hibernate整合
Spring与Struts2整合的目的: 让Spring管理Action Spring整合Hinernate的目的: --管理SessionFactory(单例的),数据源 --声明式事务管理 1.首 ...
- Mybatis学习(7)spring和mybatis整合
整合思路: 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSession.(spr ...
- MyBatis学习七:spring和MyBatis整合
<\mybatis\day02\16mybatis和spring整合-sqlSessionFactory配置.avi;> MyBatis学习七:spring和MyBatis整合.逆向工程 ...
- Spring Boot 应用系列 5 -- Spring Boot 2 整合logback
上一篇我们梳理了Spring Boot 2 整合log4j2的配置过程,其中讲到了Spring Boot 2原装适配logback,并且在非异步环境下logback和log4j2的性能差别不大,所以对 ...
- Spring Boot:整合Spring Security
综合概述 Spring Security 是 Spring 社区的一个顶级项目,也是 Spring Boot 官方推荐使用的安全框架.除了常规的认证(Authentication)和授权(Author ...
- Spring Boot:整合Spring Data JPA
综合概述 JPA是Java Persistence API的简称,是一套Sun官方提出的Java持久化规范.其设计目标主要是为了简化现有的持久化开发工作和整合ORM技术,它为Java开发人员提供了一种 ...
- SSH框架之Spring+Struts2+Hibernate整合篇
回顾 -Hibernate框架 ORM: 对象关系映射.把数据库表和JavaBean通过映射的配置文件映射起来, 操作JavaBean对象,通过映射的配置文件生成SQL语句,自动执行.操作数据库. 1 ...
随机推荐
- SVG 文本
该部分为四个主要部分: 1. <text>和<tspan>标签详解 2. 文本水平垂直居中问题 3. <textpath>让文本在指定路径上排列 4 ...
- 网站logo正确写法,个人拙见,不喜勿喷
网站logo既要考虑seo又需要用图片代替网站名字,所有H1标签带来的权重还是需要使用 有些人喜欢直接把<H1></H1>标签直接hidden掉,个人喜欢使用css Text- ...
- unable to boot the simulator,无法启动模拟器已解决
突然模拟器报错:unable to boot the simulator(无法启动模拟器) 试了好几种解决办法,删除所有的模拟器重启以后再添加,删除钥匙串登陆中的证书,重新安装Xcode都不行 最后通 ...
- 关于 Xcode8打印JSON的时候,NSLog控制台显示不完整
看到打印结果之后 为什么只打印了一部分???为什么呢??? 我也不知道为什么,可能是xcode8的原因. 借鉴了下国外人说了,printf可以打印全,自己写了个输出宏 #ifdef DEBUG #d ...
- NSURLConnection学习笔记
虽说现在都用三方库来获取网络数据,再不济也会用苹果官方的NSURLSession,但有些东西还是要先学会才有资格说不好不用,不是么? NSURLConnection发送请求是分为同步和异步两种方式的, ...
- [AlwaysOn Availability Groups]AG排查和监控指南
AG排查和监控指南 1. 排查场景 如下表包含了常用排查的场景.根据被分为几个场景类型,比如Configuration,client connectivity,failover和performance ...
- yum安装php,php-fpm
1.检查当前安装的PHP包 yum list installed | grep php 如果有安装的PHP包,先删除他们 yum remove php.x86_64 php-cli.x86_64 ph ...
- 使用Java实现单线程模式
我们都知道单例模式,有很多种实现方法.今天我们实现一个单线程实例模式,也就是说只能实例化该类的一个线程来运行,不允许有该类的多个线程实例存在.直接上代码: public class Singleton ...
- linux几种快速清空文件内容的方法
linux几种快速清空文件内容的方法 几种快速清空文件内容的方法: $ : > filename #其中的 : 是一个占位符, 不产生任何输出. $ > filename $ echo & ...
- mysql数据库主从及主主复制配置演示
实验系统:CentOS 6.6_x86_64 实验前提:提前准备好编译环境,防火墙和selinux都关闭 实验说明:本实验共有2台主机,IP分配如拓扑 实验软件:mariadb-10.0.20 实验拓 ...