spring_webservice_Hessian和Burlap配置示例
2013-10-07 13:56
465 查看
Hessian 是简化RMI的框架
Hessian服务器端
Userinfo.java
package com.lilin.entity;
import java.io.Serializable;
public class Userinfo implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
IUserinfoService.java
package com.lilin.iservice;
import com.lilin.entity.Userinfo;
public interface IUserinfoService {
public void addUserinfo(Userinfo userinfo) throws Exception;
}
UserinfoServiceImpl.java
package com.lilin.serviceimpl;
import com.lilin.entity.Userinfo;
import com.lilin.iservice.IUserinfoService;
public class UserinfoServiceImpl implements IUserinfoService{
public void addUserinfo(Userinfo userinfo) throws Exception{
System.out.println("添加了一个新的用户"+userinfo.getName());
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>spring_webservice</display-name>
<!-- 加载spring begin-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 加载spring end-->
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:remoting-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
remoting-servlet.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans ;
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop ;
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx ;
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ;
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/cache ;
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd ;
">
<bean id="userinfoService" class="com.lilin.serviceimpl.UserinfoServiceImpl"></bean>
<bean name="/UserinfoService" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property na
112fc
me="service" ref="userinfoService"/>
<property name="serviceInterface" value="com.lilin.iservice.IUserinfoService"/>
</bean>
</beans>
jar:
spring.*.jar
com.springsource.com.caucho-3.2.1.jar
启动 ok
Hessian 客户端
Userinfo.java 同上
IUserinfoService.java 同上
SimpleObject.java
package com.lilin.test;
import com.lilin.entity.Userinfo;
import com.lilin.iservice.IUserinfoService;
public class SimpleObject {
private IUserinfoService iUserinfoService;
public IUserinfoService getiUserinfoService() {
return iUserinfoService;
}
public void setiUserinfoService(IUserinfoService iUserinfoService) {
this.iUserinfoService = iUserinfoService;
}
public void add(Userinfo name) throws Exception{
iUserinfoService.addUserinfo( name );
}
}
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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans ;
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop ;
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx ;
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ;
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/cache ;
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd ;
">
<bean id="accountService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/spring_webservice/remoting/UserinfoService"/>
<property name="serviceInterface" value="com.lilin.iservice.IUserinfoService"/>
</bean>
<bean id="test" class="com.lilin.test.SimpleObject">
<property name="iUserinfoService" ref="accountService"/>
</bean>
</beans>
App.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.lilin.entity.Userinfo;
import com.lilin.test.SimpleObject;
public class App {
@org.junit.Test
public void test(){
ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");
SimpleObject object = (SimpleObject) context.getBean("test");
try {
Userinfo userinfo = new Userinfo();
userinfo.setName("=>李林");
object.add(userinfo);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Burlap 客户端
上述都不变 remoting-servlet.xml 的ServiceExporter改为org.springframework.remoting.caucho.BurlapServiceExporter
服务端修改
applicationContext.xml 的ProxyFactoryBean 为org.springframework.remoting.caucho.BurlapProxyFactoryBean
启动 ok
Hessian服务器端
Userinfo.java
package com.lilin.entity;
import java.io.Serializable;
public class Userinfo implements Serializable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
IUserinfoService.java
package com.lilin.iservice;
import com.lilin.entity.Userinfo;
public interface IUserinfoService {
public void addUserinfo(Userinfo userinfo) throws Exception;
}
UserinfoServiceImpl.java
package com.lilin.serviceimpl;
import com.lilin.entity.Userinfo;
import com.lilin.iservice.IUserinfoService;
public class UserinfoServiceImpl implements IUserinfoService{
public void addUserinfo(Userinfo userinfo) throws Exception{
System.out.println("添加了一个新的用户"+userinfo.getName());
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>spring_webservice</display-name>
<!-- 加载spring begin-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 加载spring end-->
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:remoting-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
remoting-servlet.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans ;
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop ;
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx ;
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ;
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/cache ;
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd ;
">
<bean id="userinfoService" class="com.lilin.serviceimpl.UserinfoServiceImpl"></bean>
<bean name="/UserinfoService" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property na
112fc
me="service" ref="userinfoService"/>
<property name="serviceInterface" value="com.lilin.iservice.IUserinfoService"/>
</bean>
</beans>
jar:
spring.*.jar
com.springsource.com.caucho-3.2.1.jar
启动 ok
Hessian 客户端
Userinfo.java 同上
IUserinfoService.java 同上
SimpleObject.java
package com.lilin.test;
import com.lilin.entity.Userinfo;
import com.lilin.iservice.IUserinfoService;
public class SimpleObject {
private IUserinfoService iUserinfoService;
public IUserinfoService getiUserinfoService() {
return iUserinfoService;
}
public void setiUserinfoService(IUserinfoService iUserinfoService) {
this.iUserinfoService = iUserinfoService;
}
public void add(Userinfo name) throws Exception{
iUserinfoService.addUserinfo( name );
}
}
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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans ;
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop ;
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx ;
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ;
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/cache ;
http://www.springframework.org/schema/cache/spring-cache-3.1.xsd ;
">
<bean id="accountService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/spring_webservice/remoting/UserinfoService"/>
<property name="serviceInterface" value="com.lilin.iservice.IUserinfoService"/>
</bean>
<bean id="test" class="com.lilin.test.SimpleObject">
<property name="iUserinfoService" ref="accountService"/>
</bean>
</beans>
App.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.lilin.entity.Userinfo;
import com.lilin.test.SimpleObject;
public class App {
@org.junit.Test
public void test(){
ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");
SimpleObject object = (SimpleObject) context.getBean("test");
try {
Userinfo userinfo = new Userinfo();
userinfo.setName("=>李林");
object.add(userinfo);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Burlap 客户端
上述都不变 remoting-servlet.xml 的ServiceExporter改为org.springframework.remoting.caucho.BurlapServiceExporter
服务端修改
applicationContext.xml 的ProxyFactoryBean 为org.springframework.remoting.caucho.BurlapProxyFactoryBean
启动 ok
相关文章推荐
- spring_webservice_rmi配置示例
- Java-Spring-WebService最基础的配置示例
- Java-Spring-WebService最基础的配置示例
- Java-Spring-WebService最基础的配置示例
- webservice cxf+spring+WS-security配置示例
- Spring Boot MyBatis 连接数据库配置示例
- RMI、Hessian、Burlap、Httpinvoker、WebService的比较
- 通过配置spring.xml实现通用Webservice调用
- Spring 3.1配置文件示例(备忘)
- spring配置文件加密方法示例
- java调用基于https的webservice(不生成密钥,基于spring配置,接收所有证书)
- 远程调用之RMI、Hessian、Burlap、Httpinvoker、WebService的比较
- Spring常用配置示例
- 【第十二章】零配置 之 12.5 综合示例-积分商城 ——跟我学spring3
- Quartz定时任务,Quartz Spring定时任务,spring多个定时任务Quartz配置,示例,详解
- Spring整合CXF,发布RSETful 风格-配置WebService
- Spring 3.1配置文件示例
- 以一个简单JDBC示例对比Mybatis环境配置和Spring的数据库环境配置
- Spring Boot 实现RESTful webservice服务端示例
- 基于spring+hibernate+cxf写的webservice服务,详细配置