Ved*_*ran 6 java spring hessian spring-remoting
当我通过Spring的Hessian函数调用返回BigDecimal值的远程方法时,它总是返回零.直接调用方法或使用普通的Hessian servlet(非Spring)正常工作.
可以做些什么来解决这个问题?
web.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>
Run Code Online (Sandbox Code Playgroud)
远程-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>
Run Code Online (Sandbox Code Playgroud)
我调用的方法的服务类:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
控制台应用测试:
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());
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:使用的库是Spring 3.2和Hessian 4.0.7
您可以使用 HessianServlet.setSerializerFactory() 设置您自己的 SerializerFactory 并返回 com.caucho.hessian.io.BigDecimalDeserializer 作为 BigDecimal 的反序列化器。
我们像这样修补它并且它有效。不知道为什么不以这种方式实现。