关于Spring声明式事物配置问题
本帖最后由 tracy19880727 于 2013-07-10 10:43:41 编辑 最近正在学习spring的声明式事物管理,遇到配置声明式事物后无法写入记录到数据库(数据库用的sql server 2008),话不多说,上代码:
下面是配置的声明式事物管理代码:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="add*">PROPAGATION_SUPPORTS</prop>
<prop key="query">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*ServiceImp</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
public interface FileListService {
public void add(ZipFileDto dto);
}
public class FileListServiceImp implements FileListService {
public FileListDao fileListDao;
public void setFileListDao(FileListDao fileListDao) {
this.fileListDao = fileListDao;
}
public void add(ZipFileDto dto) {
fileListDao.add(dto);
}
}
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- all methods starting with 'get' are read-only -->
<tx:method name="*TX" propagation="REQUIRED" />
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="transactioncut"
expression="execution(* *..*Service.*(..))" />
<aop:advisor advice-ref="txAdvice"
pointcut-ref="transactioncut" />
</aop:config>