hessian使用笔记(关于Hessian-servlet.xml别名问题)!

spring2.5.6  和3.1.6 以上的版本继承很有问题!~

建议使用 spring 2.5.6 + hessian 3.1.6

在web.xml加入

<!-- HESSIAN -->
  <servlet>  
    <servlet-name>Hessian</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
    	<param-name>namespace</param-name>
    	<param-value>hessian/hessian-server</param-value>
    </init-param>   
  </servlet>
  <servlet-mapping>
    <servlet-name>Hessian</servlet-name>
    <url-pattern>/hessian/*</url-pattern>
  </servlet-mapping>


namespace  这个是尼玛坑爹的,看源代码了解namespace默认为 ${servlet-name}-servlet

它要求在WEB-INF下建立一个  ${namespace}.xml的spring配置

我这里修改了

这样就OK了,看配置,这样就暴露了一个  hessian服务:

<?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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
	default-autowire="byName">
	<!-- Hessian -->
	<!-- 业务类 --> 
	<bean id="synchronizationHessian" class="com.goldpalm.tour.ws.hessian.impl.SynchronizationHessianImpl"></bean>
	<!-- 远程服务 -->  
	<bean name="/synchronizationHessian" class="org.springframework.remoting.caucho.HessianServiceExporter">
		<property name="service" ref="synchronizationHessian"/>  
		<property name="serviceInterface" value="com.goldpalm.tour.ws.hessian.SynchronizationHessian"></property>
	</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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
	default-autowire="byName">
	
	<!-- Hessian -->
	<!-- 远程服务 -->
	<bean id="synchronizationHessian" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
		<property name="serviceUrl" value="http://192.168.1.160/hessian/synchronizationHessian"/>
		<property name="serviceInterface" value="com.goldpalm.tour.ws.hessian.SynchronizationHessian"/>
	</bean>
	<!-- 定时上报 -->
	<bean id="synchronizationClientHessian" class="com.goldpalm.tour.ws.hessian.impl.SynchronizationClientHessianImpl">
	</bean>
	<bean id="methodInvokingJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject">
			<ref bean="synchronizationClientHessian" />
		</property>
		<property name="targetMethod">
			<value>run</value>
		</property>
	</bean>
	<!-- 配置触发器 -->
	<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
		<!-- 这里不可以直接在属性jobDetail中引用taskJob,因为他要求的是一个jobDetail类型的对象,所以我们得通过MethodInvokingJobDetailFactoryBean来转一下 -->
		<property name="jobDetail">
			<ref bean="methodInvokingJobDetail" />
		</property>
		<!-- 具体说明见附录 -->
		<property name="cronExpression">
			<value>0 * * * * ?</value>
		</property>
	</bean>
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<!-- 添加触发器 -->
		<property name="triggers">
			<list>
				<ref local="cronTrigger" />
			</list>
		</property>
	</bean>
</beans>


我这里用hessian完成了一个定时数据同步的功能!~

附上源代码:

由于DispatcherServlet里没有找到关于 xml读取的代码 于是我继续查看他的父类

public class DispatcherServlet extends FrameworkServlet{
//...
}

看父类doc注视

   43   /**
   44    * Base servlet for Spring's web framework. Provides integration with
   45    * a Spring application context, in a JavaBean-based overall solution.
   46    *
   47    * <p>This class offers the following functionality:
   48    * <ul>
   49    * <li>Manages a {@link org.springframework.web.context.WebApplicationContext}
   50    * instance per servlet. The servlet's configuration is determined by beans
   51    * in the servlet's namespace.
   52    * <li>Publishes events on request processing, whether or not a request is
   53    * successfully handled.
   54    * </ul>
   55    *
   56    * <p>Subclasses must implement {@link #doService} to handle requests. Because this extends
   57    * {@link HttpServletBean} rather than HttpServlet directly, bean properties are
   58    * automatically mapped onto it. Subclasses can override {@link #initFrameworkServlet()}
   59    * for custom initialization.
   60    *
   61    * <p>Detects a "contextClass" parameter at the servlet init-param level,
   62    * falling back to the default context class,
   63    * {@link org.springframework.web.context.support.XmlWebApplicationContext},
   64    * if not found. Note that, with the default FrameworkServlet,
   65    * a custom context class needs to implement the
   66    * {@link org.springframework.web.context.ConfigurableWebApplicationContext} SPI.
   67    *
   68    * <p>Passes a "contextConfigLocation" servlet init-param to the context instance,
   69    * parsing it into potentially multiple file paths which can be separated by any
   70    * number of commas and spaces, like "test-servlet.xml, myServlet.xml".
   71    * If not explicitly specified, the context implementation is supposed to build a
   72    * default location from the namespace of the servlet.
   73    *
   74    * <p>Note: In case of multiple config locations, later bean definitions will
   75    * override ones defined in earlier loaded files, at least when using Spring's
   76    * default ApplicationContext implementation. This can be leveraged to
   77    * deliberately override certain bean definitions via an extra XML file.
   78    *
   79    * <p>The default namespace is "'servlet-name'-servlet", e.g. "test-servlet" for a
   80    * servlet-name "test" (leading to a "/WEB-INF/test-servlet.xml" default location
   81    * with XmlWebApplicationContext). The namespace can also be set explicitly via
   82    * the "namespace" servlet init-param.
   83    *
   84    * @author Rod Johnson
   85    * @author Juergen Hoeller
   86    * @author Sam Brannen
   87    * @see #doService
   88    * @see #setContextClass
   89    * @see #setContextConfigLocation
   90    * @see #setNamespace
   91    */
   92   public abstract class FrameworkServlet extends HttpServletBean implements ApplicationListener {

直接坑爹了,我们查看下 namespace的访问其 看看支持修改不

直接看到 有 setNamespace方法 和 getNamespace

代码是

  189   	/**
  190   	 * Return the namespace for this servlet, falling back to default scheme if
  191   	 * no custom namespace was set: e.g. "test-servlet" for a servlet named "test".
  192   	 */
  193   	public String getNamespace() {
  194   		return (this.namespace != null) ? this.namespace : getServletName() + DEFAULT_NAMESPACE_SUFFIX;
  195   	}


所以我们设置namespace就可以修改了!~

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值