首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

使用ssh整合时出现的异常

2014-01-15 
使用ssh整合时出现的错误在使用接口测试的时候出现Exception in thread main java.lang.ClassCastExcept

使用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.xml</value>
</list>
</property>
</bean>
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
 <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>

 <tx:advice id="x" transaction-manager="transactionManager">
 <tx:attributes>
 <tx:method name="do*" propagation="REQUIRED"/>
 </tx:attributes>
 </tx:advice>

 <aop:config>
 <aop:pointcut id="m" expression="execution(* com.accp.service.*.*(..))"/>
 <aop:advisor advice-ref="x" pointcut-ref="m" />
 </aop:config>

<bean id="auth" class="com.accp.aop.userinfo.AuthorityManager"></bean>

<bean id="proxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="interceptorNames">
<list>
<value>auth</value>
</list>
</property>
<property name="beanNames">
<value>userinfoService</value>
</property>
</bean>


<bean id="userinfoDao" class="com.accp.dao.impl.UserinfoDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="userinfoService" class="com.accp.service.impl.UserinfoServiceImpl">
<property name="dao" ref="userinfoDao"></property>
</bean>
<bean id="userinfoLoginAction" class="com.accp.action.userinfo.LoginAction">
<property name="manager" ref="auth"></property>
<property name="service" ref="userinfoService"></property>
</bean>
<bean id="userinfoFindAction" class="com.accp.action.userinfo.FindAction">


<property name="service" ref="userinfoService"></property>
</bean>
<bean id="atmDrawAction" class="com.accp.action.userinfo.ATMDrawAction">
<property name="service" ref="userinfoService"></property>
</bean>
</beans>


[解决办法]
你打断点追一下,在dao实现doDraw方法里面 和service实现里面  看看走到哪里报的错。

热点排行