Spring 版本是 3.1
Hibernate 是 4.1.4 final
我想使用spring的BeanNameAutoProxyCreator将Service结尾的bean里面的一些方法自动开启事务
相关配置如下
        <bean id="userService" class="test.service.impl.UserServiceImpl">
<property name="userDAO">
<ref local="userDAO"/>
</property>
</bean>
<bean id="userDAO" name="userDAO"  class="test.dao.impl.UserDAO">
<property name="session" ref="session" />
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />

<property name="transactionAttributes">
<props>
<prop key="save">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
---------------
补充:
bean配置都正常的,而我再测试类直接取session自己开启事务保存是可以写到数据库
而取userService.save方法,里面有userDAO.save方法,但是因为没开启事务,所以没有写到数据库,也没有相关的SQL语句打印出来!