当我通过 Spring 的 Hessian 功能调用返回 BigDecimal 值的远程方法时,它总是返回零。直接调用该方法或使用普通的 Hessian servlet(非 Spring)可以正常工作。
可以做些什么来解决这个问题?
服务器端(Tomcat 7)
网页.xml:
<?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">
<servlet>
<servlet-name>remoting</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>remoting</servlet-name>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
</web-app>
远程处理-servlet.xml:
<beans>
<context:annotation-config />
<context:component-scan base-package="hr.spi.logic.lcspi" />
<tx:annotation-driven proxy-target-class="true" />
<bean name="/lcspi/lc302/poslovi" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="posloviLogic" />
<property name="serviceInterface" value="hr.spi.logic.lcspi.lc302.PosloviLogicInterface" />
</bean>
</beans>
我调用其方法的服务类:
package hr.spi.logic.lcspi.lc302;
@Transactional
@Repository
public class PosloviLogic implements PosloviLogicInterface {
@Override
public BigDecimal test()
{
BigDecimal bd = new BigDecimal("2.2");
return bd;
}
}
客户端
Spring配置-applicationContextHessian.xml:
<beans>
<bean id="posloviLogic" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/SpringWebTest/remoting/lcspi/lc302/poslovi" />
<property name="serviceInterface" value="hr.spi.logic.lcspi.lc302.PosloviLogicInterface" />
</bean>
</beans>
控制台应用测试:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContextHessian.xml");
try {
PosloviLogicInterface posloviLogic = (PosloviLogicInterface) context.getBean("posloviLogic");
BigDecimal bd = posloviLogic.test();
System.out.println(bd); // This returns 0.00
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
编辑:使用的库是 Spring 3.2 和 Hessian 4.0.7