Spring配置Hessian
1.创建web工程,并加载spring、hessian框架2.创建service:[java]public interface BasicService {public void setServiceName(String serverName);public String getServiceName();public User createUser();}2.创建service实现:public class BasicServiceImpl implements BasicService {private String serviceName;@Overridepublic void setServiceName(String serverName) {this.serviceName = serverName;}@Overridepublic String getServiceName() {return this.serviceName;}@Overridepublic User createUser() {return new User("zhangsan", "123456");}}3.创建需要传递的对象:[java]public class User implements Serializable {private static final long serialVersionUID = 5792818254468116836L;private String username;private String password;public User(String username, String password) {this.username = username;this.password = password;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}4.配置web.xml,利用dispatchServlet处理请求:[html]<?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_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>HessianSpringServer</display-name><servlet><servlet-name>remote</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:com/loujinhe/config/remote-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>remote</servlet-name><url-pattern>/remote/*</url-pattern></servlet-mapping></web-app>5.配置remote-servlet.xml:[html]<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="basicService" class="com.loujinhe.service.impl.BasicServiceImpl"/><bean id="hessianRemote" name="/HessianRemote" class="org.springframework.remoting.caucho.HessianServiceExporter"><property name="serviceInterface" value="com.loujinhe.service.BasicService"/><property name="service" ref="basicService"/></bean></beans>6.创建客户端调用工程,并加载spring、hessian框架7.创建service和普通需要传递的对象8.配置remote-client.xml[html]<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="basicService" class="com.loujinhe.service.impl.BasicServiceImpl"/><bean id="hessianRemote" name="/HessianRemote" class="org.springframework.remoting.caucho.HessianServiceExporter"><property name="serviceInterface" value="com.loujinhe.service.BasicService"/><property name="service" ref="basicService"/></bean></beans>9.创建客户端测试程序:[java]public class RemoteTest {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("com/loujinhe/config/remote-client.xml");&nbs补充:软件开发 , Java ,
上一个:java.lang.IllegalStateException: Web app root system property already set to different value
下一个:Hessian
- 更多JAVA疑问解答:
- java怎么在线读取ftp服务器上的文件内容
- 关于程序员的职业规划
- HTML和JSP矛盾吗?
- java小程序如何打包?
- java怎么split路径文件名?
- 关于Hibernate实体自身多对一的抓取问题
- 关于apache2+tomcat群集出现的问题
- SSH 导入导出excel 谁有这块的资料吗?
- springmvc 加载一个jsp页面执行多个方法 报404
- 关于用jquery 导入 excel
- java对时间进行循环放到List中
- 一个图片的输入输出程序,第一次调用某方法会中断,第二次调用则正常
- 请上过传智播客的人说一下传智播客怎么样呀!是不是像它说的那样好呀!
- spring的schema怎么配置
- 【菜鸟求助】SSH中怎么从JSP页面往后台传值呢