1.服务端与Spring的整合

1.1:web.xml中配置控制器

    <servlet>
<servlet-name>hessian</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- Spring的配置 -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
</servlet> <servlet-mapping>
<servlet-name>hessian</servlet-name>
<url-pattern>/hessian/*</url-pattern>
</servlet-mapping>

1.2:编写接口和实现类

接口:

package com.hessian.service;

import com.hessian.domain.User;

public interface HessianFunc {

    public String getAddressByMobille(String phone);

    public void saveUser(User user);

}

实现类:

package com.hessian.service;

import com.hessian.domain.User;

public class HsessianFuncImpl implements HessianFunc {

    @Override
public String getAddressByMobille(String phone) { String result="手机号"+phone+"的归属地是上海....."; return result;
} @Override
public void saveUser(User user) { System.out.println(user.getName()+"---"+user.getAge());
}
}

需要一个实体类:

package com.hessian.domain;

import java.io.Serializable;

public class User implements Serializable{

    /**
* 一定要实例化
*/
private static final long serialVersionUID = 1L;
private Integer id;
private String name;
private Integer age; public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}

1.3:编写applicationContext.xml  交给Spring管理

<?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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="/mobile" class="org.springframework.remoting.caucho.HessianServiceExporter">
<!-- 接口类型 -->
<property name="serviceInterface" value="com.hessian.service.HessianFunc"></property>
<!-- 接口对象 -->
<property name="service" ref="HsessianFuncImpl"></property>
</bean> <bean id="HsessianFuncImpl" class="com.hessian.service.HsessianFuncImpl"></bean> </beans>

访问地址:http://localhost:8080/HessionSpringServer/hessian/mobile

2.客户端与Spring整合:

2.1:因为要用到User和接口,这里包装成jar包即可

2.2:配置applicationContext.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.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--创建代理工厂的核心对象-->
<bean id="hessianProxy" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
    <!--服务接口-->
<property name="serviceInterface" value="com.hessian.service.HessianFunc"></property>
    <!--服务地址-->
<property name="serviceUrl" value="http://localhost:8080/HessionSpringServer/hessian/mobile"></property>
</bean>
</beans>

2.3:编写测试代码:

package com.hessian.test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.hessian.domain.User;
import com.hessian.service.HessianFunc; public class TestHessian {
public static void main(String[] args) { ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); HessianFunc func = (HessianFunc) ac.getBean("hessianProxy"); String mobille = func.getAddressByMobille("1888888888"); System.out.println(mobille); User user = new User();
user.setAge(12);
user.setName("jack"); func.saveUser(user);
}
}

Hessian与Spring整合的更多相关文章

  1. hessian的简单使用以及与spring整合

    Hessian是一个由Caucho Technology开发的轻量级二进制RPC协议.和其他Web服务的实现框架不同的是,Hessian是一个使用二进制格式传输的Web服务协议的框架,相对传统soap ...

  2. Spring整合Hessian

    Spring让Hessian变得不但强大,而且易用,但是易用背后,却有不少陷阱!   这个例子很简单,但实际上的确花费了我超过一小时的时间,排除了种种问题,最后问题终于水落石出.   整合以上篇Hel ...

  3. Spring整合Hessian访问远程服务

    声明:该文章转载自Spring整合Hessian访问远程服务,本人搬过来只是为了记录下学习Hessian的过程,忘此博主理解,在此感谢,等本人有能力了再学一些原创的东东,本人实践了下,hessianS ...

  4. 使用Spring整合Quartz轻松完成定时任务

    一.背景 上次我们介绍了如何使用Spring Task进行完成定时任务的编写,这次我们使用Spring整合Quartz的方式来再一次实现定时任务的开发,以下奉上开发步骤及注意事项等. 二.开发环境及必 ...

  5. 【Java EE 学习 53】【Spring学习第五天】【Spring整合Hibernate】【Spring整合Hibernate、Struts2】【问题:整合hibernate之后事务不能回滚】

    一.Spring整合Hibernate 1.如果一个DAO 类继承了HibernateDaoSupport,只需要在spring配置文件中注入SessionFactory就可以了:如果一个DAO类没有 ...

  6. spring整合hibernate的详细步骤

    Spring整合hibernate需要整合些什么? 由IOC容器来生成hibernate的sessionFactory. 让hibernate使用spring的声明式事务 整合步骤: 加入hibern ...

  7. Spring整合Ehcache管理缓存

    前言 Ehcache 是一个成熟的缓存框架,你可以直接使用它来管理你的缓存. Spring 提供了对缓存功能的抽象:即允许绑定不同的缓存解决方案(如Ehcache),但本身不直接提供缓存功能的实现.它 ...

  8. spring整合hibernate

    spring整合hibernate包括三部分:hibernate的配置.hibernate核心对象交给spring管理.事务由AOP控制 好处: 由java代码进行配置,摆脱硬编码,连接数据库等信息更 ...

  9. MyBatis学习(四)MyBatis和Spring整合

    MyBatis和Spring整合 思路 1.让spring管理SqlSessionFactory 2.让spring管理mapper对象和dao. 使用spring和mybatis整合开发mapper ...

随机推荐

  1. 第二章----python基础

    概要:python是一种计算机编程语言,有自己的一套语法,编译器或者解释器负责把符合语法的程序代码翻译成CPU能识别的机器码,然后执行.python使用缩进来组织代码块,Python程序中大小写是敏感 ...

  2. jpofiler监控JVM

    1.官方下载地址,选择自己想要的版本 https://www.ej-technologies.com/download/jprofiler/version_92 2.分为linux服务端.window ...

  3. hoj 2715 (费用流 拆点)

    http://acm.hit.edu.cn/hoj/problem/view?id=2715 将每个格子 i 拆成两个点 i’, i’’并加边(i’, i’’, 1, -Vi), (i’, i’’, ...

  4. CodeIgniter框架——源码分析之CodeIgniter.php

    CodeIgniter.php可以说是CI的核心,大部分MVC的流程都是在这个文件夹中处理的,其中加载了很多外部文件,完成CI的一次完整流程. 首先是定义了CI的版本(此处为CI 2.2.0),接下来 ...

  5. Partial Sum

    Partial Sum Accepted : 80   Submit : 353 Time Limit : 3000 MS   Memory Limit : 65536 KB  Partial Sum ...

  6. 深入C#学习系列一:序列化(Serialize)、反序列化(Deserialize)(转)

    序列化又称串行化,是.NET运行时环境用来支持用户定义类型的流化的机制.其目的是以某种存储形成使自定义对象持久化,或者将这种对象从一个地方传输到另一个地方.    .NET框架提供了两种串行化的方式: ...

  7. 《挑战程序设计竞赛》2.1 广度优先搜索 AOJ0558 POJ3669 AOJ0121

    AOJ0558 原文链接: AOJ0558 题意: 在H * W的地图上有N个奶酪工厂,分别生产硬度为1-N的奶酪.有一只吃货老鼠准备从老鼠洞出发吃遍每一个工厂的奶酪.老鼠有一个体力值,初始时为1,每 ...

  8. cmake编译选项

    1 需求 现在已经有一个cmake工程,我想要添加-O0 -g,生成gdb的调试信息和不进行代码优化. 也就是说,我该怎样修改CFLAGS和CPPFLAGS? 2 在project后面添加 set(C ...

  9. 一篇搞定SQLAlchemy--关系对象映射

    要使用SQLAlchemy,必须先下载这个模块 pip3 install sqlalchemy 或 pycharm File--> Settings-->project...-->P ...

  10. Django中_Meta 部分用法

    周一了,就不长篇大论了,给大家分享一个很实用的知识点,希望大家周末过得开心,愉快,诗和远方在等着你们.而我还在苦逼的撸代码,只为了应付眼前的苟且! model.UserInfo._meta.app_l ...