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

帮手看下SSH
<bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
  <ref bean="transactionManager" />
  </property>
  <property name="target">
  <ref local="usersDAO" />
  </property>
  <property name="transactionAttributes">
  <props>
  <prop key="insert*">PROPAGATION_REQUIRED</prop>
  <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
  <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
  </props>
  </property>
 </bean>

<bean id="usersDAO" class="my.dao.hibernate.UsersDAO"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="usersManager" class="my.service.impl.UsersManager"
abstract="false" lazy-init="default" autowire="default"
dependency-check="default">
<property name="usersDAO">
<ref bean="userDAOProxy" />
</property>
</bean>

请问各位:spring的事务代理是这样子用的吗??

报错:
Failed to convert property value of type [$Proxy3] to required type [my.dao.hibernate.UsersDAO] for property 'usersDAO'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy3] to required type [my.dao.hibernate.UsersDAO] for property 'usersDAO': no matching editors or conversion strategy found



------解决方案--------------------
你的my.dao.hibernate.UsersDAO这个bean需要设置属性proxyTargetClass为true,这样产生的代理对象才会instanceof原来的类。
在事务中加上下面语句
<property name="proxyTargetClass" >
<value>true</value>
</property>
表面proxy代理的是类而不是接口。