SPRINGMVC Integrated Hessian
The first emphasis here is SPRINGMVC, not spring, both of which are different when integrating Hessian. Spring integration is relatively simple, just search the web on the line.
Springmvc a little trouble.
Note: If you do not know Hessian, you can see Hessian simple example
Pre-conditions
Let's say your SPRINGMVC environment is already configured.
The following configuration is primarily available in Web. xml:
<servlet> <!-- 名字随便,和你springmvc的配置xml一致即可 --> <servlet-name>sys</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <!-- 你自己的映射配置 --></servlet-mapping>
In addition you have configured the corresponding sys-servlet.xml file ( sys name and your own consistency can be).
Integrated Hessian
In order to request for Hessian, the web.xml following mappings have been added:
<servlet-mapping> <!-- 名字要保持一致 --> <servlet-name>sys</servlet-name> <url-pattern>*.hessian</url-pattern></servlet-mapping>
Then sys-servlet.xml add the following configuration in:
<!--hessian--><bean id="httpRequestHandlerAdapter" class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/><bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/><bean id="importService" class="com.xxx.pr.service.impl.ImportServiceImpl"/><bean name="/import.hessian" class="org.springframework.remoting.caucho.HessianServiceExporter"> <property name="service" ref="importService"/> <property name="serviceInterface" value="com.xxx.pr.service.ImportService"/></bean>
HessianServiceExporteris an inherited HttpRequestHandler interface, so you need HttpRequestHandlerAdapter to handle this request.
BeanNameUrlHandlerMappingThe function is to <bean> name / map a URL request when the property starts with.
HessianServiceExporterThe two properties in the, one is service the ref implementation class that the property points to. One is serviceInterface , the point is the interface.
After the configuration is done, start the server.
Then visit Http://localhost:8080/myweb/import.hessian . The specific address according to their own to write.
When the browser opens, the following appears:
HTTP Status 405-hessianserviceexporter only supports POST requests
type Status Report
message Hessianserviceexporter only supports POST requests
Description The specified HTTP method isn't allowed for the requested resource.
Apache tomcat/7.0.56
If shown above, there is no problem with the instructions.
Call if called in spring, you can try the following configuration
<bean id="importBean" class="org.springframework.remoting.caucho.HessianProxyFactoryBean"> <property name="serviceUrl" value="http://localhost:8080/myweb/import.hessian"></property> <property name="serviceInterface" value="com.xxx.pr.service.ImportService"></property>
You can also call directly using Hessian
String url = "http://localhost:8080/myweb/import.hessian";HessianProxyFactory factory = new HessianProxyFactory();ImportService basic = (ImportService) factory.create(ImportService.class, url);
SPRINGMVC Integrated Hessian