日期:2014-05-17  浏览次数:20988 次

使用ssh整合时出现的错误
在使用接口测试的时候出现
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at com.sun.proxy.$Proxy5.doDraw(Unknown Source)
at com.accp.service.impl.UserinfoServiceImpl.main(UserinfoServiceImpl.java:45)

用这段代码可以通过测试
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
UserinfoDao dao = (UserinfoDao) context.getBean("userinfoDao");
Userinfo userinfo = dao.findByBankNo(new BigDecimal("2222222222222222222"));
userinfo.setBalance(userinfo.getBalance()-100);
System.out.println(dao.doDraw(userinfo));
}

但是换成这段代码就不能通过测试了
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
UserinfoService service = (UserinfoService) context.getBean("userinfoService");
Userinfo userinfo = service.findByBankNo(new BigDecimal("2222222222222222222"));
userinfo.setBalance(userinfo.getBalance()-100);
System.out.println(service.doDraw(userinfo));
}


Spring的配置文件beans.xml的代码
<?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:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl">
</property>
<property name="username" value="c##accp"></property>
<property name="password" value="accp"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/accp/po/Popedom.hbm.xml</value>
<value>com/accp/po/Loan.hbm.xml</value>
<value>com/accp/po/Deptpopedom.hbm.xml</value>
<value>com/accp/po/Userinfo.hbm.xml</value>
<value>com/accp/po/Dept.hbm.xml</value>
<value>com/accp/po/Loginfo.hbm.xml</value>
<value>com/accp/po/Employee.hbm.xml</value>
<value>com/accp/po/Exchange.hbm