标签:
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <argLine>-Dfile.encoding=UTF-8</argLine> <spring.version>4.1.6.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.annotation</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.ejb</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>org.jboss.weld</groupId> <artifactId>weld-osgi-bundle</artifactId> <version>1.0.1-SP3</version> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.servlet</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>com.caucho</groupId> <artifactId>hessian</artifactId> <version>4.0.38</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> </dependencies>
<?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" version="3.0"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:spring*.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>remoting</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:remoting-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>remoting</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping> </web-app>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- 接口的具体实现类 --> <!-- <bean id="loginTestInterfa" class="com.cn.wddqz.manage.impl.LoginTestImpl" /> --> <!-- 使用Spring的HessianServie做代理 --> <bean name="/loginTestInterfa" class="org.springframework.remoting.caucho.HessianServiceExporter"> <!-- service引用具体的实现实体Bean--> <property name="service" ref="loginTestInterfa" /> <property name="serviceInterface" value="com.cn.wddqz.manage.LoginTestInterfa" /> </bean> </beans>
<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <!-- 设置使用注解的类所在的jar包 --> <context:component-scan base-package="com.cn.wddqz"></context:component-scan> <!-- 完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/> </beans>
package com.cn.wddqz.manage; /** * Hessian Server的接口需要暴露给client使用 * 类名称:LoginTestInterfa * 类描述: * 创建人:wodediqizhang@163.com * 修改时间:2016-6-20 下午4:22:02 * Modification History: * ============================================================================= * Author Date Description * ------------ ---------- --------------------------------------------------- * ghb 2016-6-20 创建文档 * ============================================================================= * @version 1.0.0 * */ public interface LoginTestInterfa { public String qualifyInfo(String name,String mail) ; }
package com.cn.wddqz.manage.impl; import com.cn.wddqz.manage.LoginTestInterfa; import org.springframework.stereotype.Service; /** * Hessian Server的接口实现,client调用接口,会在这里进行业务处理 * 类名称:LoginTestImpl * 类描述: * 创建人:wodediqizhang@163.com * 修改时间:2016-6-20 下午4:22:44 * Modification History: * ============================================================================= * Author Date Description * ------------ ---------- --------------------------------------------------- * ghb 2016-6-20 创建文档 * ============================================================================= * @version 1.0.0 * */ @Service("loginTestInterfa") public class LoginTestImpl implements LoginTestInterfa { @Override public String qualifyInfo(String name, String mail) { System.out.println("Hessian Server 接口调用"); return "名字:["+name+"],邮箱:["+mail+"]"; } }
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <argLine>-Dfile.encoding=UTF-8</argLine> <spring.version>4.1.6.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.annotation</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.ejb</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>org.jboss.weld</groupId> <artifactId>weld-osgi-bundle</artifactId> <version>1.0.1-SP3</version> </dependency> <dependency> <groupId>org.glassfish</groupId> <artifactId>javax.servlet</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>com.caucho</groupId> <artifactId>hessian</artifactId> <version>4.0.38</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>hessianSer</groupId> <artifactId>hessianSer</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency><pre name="code" class="java"></dependencies>
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:context.xml </param-value> </context-param> <!-- Start 配置上下文载入器 --> <!-- 上下文载入器载入除DispatcherServlet载入的配置文件之外的其它上下文配置文件 --> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- 可以自定义servlet.xml配置文件的位置和名称,默认为WEB-INF目录下,名称为[<servlet-name>]-servlet.xml,如spring-servlet.xml <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring-servlet.xml</param-value> 默认 </init-param> --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <!-- 最常用的上下文载入器是一个Servlet监听器,其名称为ContextLoaderListener --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- End 配置上下文载入器 --> </web-app>
<?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/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="ignoreResourceNotFound" value="true" /> <property name="locations"> <list> <value>classpath:hessian.properties</value> </list> </property> </bean> <!--客户端Hessian代理工厂Bean--> <bean id="loginTestInterfa" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"> <!--这是因为接口中出现方法重载,在调用时,服务器端会跑出异常 。在整合spring中,在客户端的配置里面加上如下代码可以解决:--> <property name="overloadEnabled" value="true" /> <!--请求代理Servlet路径:--> <property name="serviceUrl" value="${hessian.url}loginTestInterfa" /> <!--接口定义:--> <property name="serviceInterface" value="com.cn.wddqz.manage.LoginTestInterfa" /> </bean> </beans>
#配置文件 hessian.url=http\://localhost\:8080/HessianSer/remoting/
<?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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> <!-- 设置使用注解的类所在的jar包 --> <context:component-scan base-package="com.cn.wddqz.web"></context:component-scan> <!-- 完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- 定义JSP --> <!-- 对转向页面的路径解析。prefix:前缀, suffix:后缀 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> </beans>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>测试Hessian</title> </head> <body> <div style="TEXT-ALIGN: center;MARGIN-RIGHT: auto; MARGIN-LEFT: auto; "> <form action="login" method="post"> <div> <label for="name">姓名:</label> <input class="easyui-validatebox" type="text" name="name" data-options="required:true" /> </div> <div> <label for="email">邮箱:</label> <input class="easyui-validatebox" type="text" name="email" data-options="validType:'email'" /> </div> <div> <button type="submit">登录</button> </div> </form> </div> </body> </html>
package com.cn.wddqz.web; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; import com.cn.wddqz.manage.LoginTestInterfa; /** * 通过Controller调用hessian接口 * 类名称:IndexController * 类描述: * 创建人:wodediqizhang@163.com * 修改时间:2016-6-20 下午4:22:02 * Modification History: * ============================================================================= * Author Date Description * ------------ ---------- --------------------------------------------------- * ghb 2016-6-20 创建文档 * ============================================================================= * @version 1.0.0 * */ @Controller public class IndexController { @Autowired private LoginTestInterfa loginTestInterfa; @RequestMapping("/login") public ModelAndView indexView(HttpServletRequest request) { String name = request.getParameter("name"); String email = request.getParameter("email"); String loginInfo = loginTestInterfa.qualifyInfo(name,email); System.out.println("loginInfo="+loginInfo); ModelAndView mv = new ModelAndView(); mv.addObject("message", loginInfo); return mv; } }
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>显示内容</title> </head> <body> ${message }; </body> </html>
Hessian知识学习总结(三)——Spring + Hessian + Spring MVC
标签:
原文地址:http://blog.csdn.net/wodediqizhang/article/details/51723821