把事务放在service层,项目的目录结构是
+com
+owner
+dao
OwnerDao.java
+service
OwnerService.java
+param
+bp
+dao
BpDao.java
+service
BpService.java
spring +ibatis 下 配置aop 事务的 代码如下:
<bean id="transactionManager_Apprsal"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource_apprsal"></property>
</bean>
<tx:advice id="txAdvice_Apprsal" transaction-manager="transactionManager_Apprsal">
<tx:attributes>
<tx:method name="login" propagation="REQUIRED" />
<tx:method name="signOut" propagation="REQUIRED" />
<tx:method name="create*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="copy*" propagation="REQUIRED"/>
<tx:method name="getSerial" propagation="REQUIRED"/>
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="allDAO_Apprsal"
expression="execution(* com.easepal..service.*Service.*(..))" />
<aop:advisor advice-ref="txAdvice_Apprsal" pointcut-ref="allDAO_Apprsal" />
</aop:config>
但是这样配置的 不成功
------解决方案--------------------
楼主DAO层的sqlmapclient是怎么注入的,要生效你必需用spring的sqlmapclient,
SqlMapClientFactoryBean这个类是工厂类,不能够让ibatis自己加载
- XML code
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="/WEB-INF/sqlmap-config.xml"/> <!-- iBatis sqlmap config 文件位置 --> <property name="dataSource" ref="dataSource"/> <!-- 在SpringFramework配置文件中使用的数据源 --> </bean>