Create two Web applications as a Hessian server and another as a client
server-side code
First set up the Hessian server side, create a new Web project, project name Hessian, the main jar package required:
Configure Web.xml,
<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:hessian.xml</ param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name >remote</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping >
The Hessian.xml file is configured as follows
<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" xmln
S:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" 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/contex T http://www.springframework.org/schema/context/spring-context-3.0.xsd "> <bean id=" Helloimpl "CLA ss= "Com.hessian.s.helloimpl" ></bean> <bean name= "/hessapi" Org.springframework.remoting.caucho.HessianServiceExporter "> <property name=" service "ref=" Helloimpl "> </property> <property name= "Serviceinterface" value= "Com.hessiAn.s.hello "></property> </bean> </beans>
Interface code:
Package com.hessian.s;
/**
* @author work
* Exposure interface
/public interface Hello {public
void say (String name);
Implementation code:
Package com.hessian.s;
/**
* Specific implementation
* @author work/public
class Helloimpl implements hello{
@Override
Public void Say (String name) {
//TODO auto-generated method stub
System.out.println ("Hello" +name);
}
Server-side configuration complete, can be deployed on Tomcat test, test code:
Hessianproxyfactory FC = new Hessianproxyfactory ();
Hello hello = (hello) fc.create (Hello.class, "Http://localhost:8080/hessian/api/hessApi");
Hello.say ("World");
Client code
Create a Web project SMVC, add the above jar package, and configure the Web.xml code as follows:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class> Org.springframework.web.servlet.DispatcherServlet </servlet-class>
<init-param>
< Param-name>contextconfiglocation</param-name>
<param-value>classpath:springmvc.xml</ param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name >dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping >
The Springmvc.xml configuration file is as follows:
<context:component-scan base-package= "Com.sun.c1" ></context:component-scan>
<bean class= " Org.springframework.web.servlet.view.InternalResourceViewResolver ">
<property name=" prefix "value="/ jsp/"></property>
<property name=" suffix "value=". JSP ></property>
</bean>
<bean id= "Hello" class= "Org.springframework.remoting.caucho.HessianProxyFactoryBean" >
< Property Name= "serviceurl" value= "Http://localhost:8080/hessian/api/hessApi" ></property>
< Property Name= "Serviceinterface" value= "Com.hessian.s.hello" ></property>
</bean>
The controller code is as follows:
@Controller
@RequestMapping ("/aug") public
class Augcontroller {
@Autowired
@Qualifier ("Hello")
private Hello Helloimpl;
@RequestMapping ("/hello.do") public
String Hello (modelandview mv) {
System.out.println ("Hello");
Helloimpl.say ("World");
Return "Success";
}
Deploy all two projects under Tomcat, access through the browser: Http://localhost:8080/smvc/aug/hello.do can see the client SPRINGMVC call to the Hessian server side
Code Download Address: http://download.csdn.net/detail/sunqingzhong44/9592865