spring+ibatis配置事务报错 !!!!!!!!求教

zw87804600 2010-06-11 10:55:43
spring配置文件

<!-- 指定连接文件路径 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:db.properties</value>
</property>
</bean>


<!-- 相关数据源和事务管理的定义 -->

<bean id="dataSource"

class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

<property name="driverClassName" value="${jdbc.driverClassName}"/>

<property name="url" value="${jdbc.url}"/>

<property name="username" value="${jdbc.username}"/>

<property name="password" value="${jdbc.password}"/>

</bean>

<!-- Transaction manager for a single JDBC DataSource -->

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager"
ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>HumanImp</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>




<!-- Spring提供的iBatis的SqlMap配置-->

<bean id="SqlMapClient"

class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">

<property name="configLocation" value="classpath:com/maps/SqlMapConfig.xml"/>

<property name="dataSource" ref="dataSource"/>

</bean>

<bean id="sqlMapClientTemplate"
class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient">
<ref bean="SqlMapClient" />
</property>
</bean>


<bean id="HumanImp" class="com.dao.humandao.HumanImp">
<property name="sqlmapclienttemplate" ref="sqlMapClientTemplate"></property>
</bean>


</beans>



总报错:
Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to com.dao.humandao.HumanImp
at test.Test.main(Test.java:23)

请帮忙解决一下 不要拿网上那些看不懂的方法告诉我
...全文
130 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jumpheightway 2010-06-11
  • 打赏
  • 举报
回复
你用代理
代理转换出错
如果你用的是接口则只能够转换成接口
zw87804600 2010-06-11
  • 打赏
  • 举报
回复
请教高手贴一个事务配置的XML文件让我学习学习 我用的上就给分
zw87804600 2010-06-11
  • 打赏
  • 举报
回复
我那是一个类啊
<bean id="HumanImp" class="com.dao.humandao.HumanImp">
<property name="sqlmapclienttemplate" ref="sqlMapClientTemplate"></property>
</bean>
这样写 就可以在 TEST类中 得到这个类的 我SSH 就是这样测试的
没问题啊 我就是想测试 事物 是不是有用
Java技术栈 2010-06-11
  • 打赏
  • 举报
回复
HumanImp mm1=(HumanImp) context.getBean("HumanImp"); 这个转型异常

怎么得到spring中的 bean 楼主Gg下
kevinho1985 2010-06-11
  • 打赏
  • 举报
回复
你看看 com.dao.humandao.HumanImp 这个方法,应该是在做类型转换的时候出错了。
javaisthis 2010-06-11
  • 打赏
  • 举报
回复
配置没问题,你写的类有问题,com.dao.humandao.HumanImp这个必须是能被实例化的类
zw87804600 2010-06-11
  • 打赏
  • 举报
回复
public static void main(String[] args) {
// TODO Auto-generated method stu
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");

//LoginImp mm1=(LoginImp) context.getBean("LoginImp");
//System.out.print(mm1.checked("zw", "123"));
HumanImp mm1=(HumanImp) context.getBean("HumanImp");
List list=mm1.findall();
for(int i=0 ; i<list.size() ;i++){
if(i>1){
System.out.println("列表太长,中断事务");
throw new RuntimeException("中断事务异常,当列表长度大于3的时候故意抛出,看看事务是否回滚");
}
Student stu = (Student)list.get(i);
mm1.save(stu);
}


}
Java技术栈 2010-06-11
  • 打赏
  • 举报
回复
Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to com.dao.humandao.HumanImp
at test.Test.main(Test.java:23)

看看23行代码 全贴出来吧
zw87804600 2010-06-11
  • 打赏
  • 举报
回复
都没人回答么

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧