关于java的BigDecimal类型经Hessian发布出现Bug的示例
我用的Hessian是Hessian 4.0.7版本
我们用它与spring集成
以下是web.xml内容
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/classes/*-context.xml</param-value></context-param><listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet><servlet-name>remoting</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/*-remote.xml</param-value> </init-param> <load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>remoting</servlet-name><url-pattern>/remoting/*</url-pattern></servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
<?xml version="1.0" encoding="gb2312"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- 此文件定义上下文内容,各模块需各自按以下指定的文件名在各模块的src文件夹下维护、管理上下文内容。此文件只作管理用途,不允许随意修改!--> <bean name="/remoteLoginService" ref="fap.loginService"/> <property name="serviceInterface" value="grp.pt.common.ILoginService"/> </bean> <!-- 用户管理 --> <bean name="/remoteUserService" ref="fap.userService"/> <property name="serviceInterface" value="grp.pt.common.IUserService"/> </bean> <bean name="/remoteTest" ref="testbean"/> <property name="serviceInterface" value="grp.pt.common.ITestService"/> </bean> </beans>
<bean id="testbean" name="code">package grp.pt.common;import java.math.BigDecimal;public interface ITestService {public BigDecimal testBig();public float testfloat();public double testdouble();}
package grp.pt.common.bs;import grp.pt.common.ITestService;import java.math.BigDecimal;public class TestService implements ITestService {public BigDecimal testBig() {BigDecimal big=new BigDecimal( "10.90944" );System.out.println("服务端:"+big);return big;}public double testdouble(){return 10.123d;}public float testfloat(){return 10.123f;}}
public static void main(String[] args) throws Exception { String url = "http://localhost:8080/realware/remoting/remoteTest"; HessianProxyFactory factory = new HessianProxyFactory(); ITestService test = (ITestService) factory.create(ITestService.class,url); BigDecimal bi=test.testBig(); System.out.println(test.testdouble()); System.out.println(test.testfloat()); System.out.println(new BigDecimal(bi.toString())); BigDecimal big=new BigDecimal("10.123"); System.out.println(big.toString());}
10.12310.1230.0000010.123
服务端:10.90944