<!-- 配置dao层 扫描 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.gxa.bj.daoimp"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- 在spring中声明事务的配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="jdbcDataSource" />
</bean>
<!-- 事务增强的配置 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 事务属性的配置,配置都哪些方法上 -->
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="add*" rollback-for="Exception"/>
<tx:method name="remove*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="serviceCut" expression="execution(public * com.gxa.bj.service.*.*(..))" />
<aop:advisor pointcut-ref="serviceCut" advice-ref="txAdvice" />
</aop:config>
例子:增强Service层记录时间的方法
<!-- 配置AOP -->
<bean id="recordTimebean" class="com.gxa.bj.aspect.RecordTime"></bean>
<bean id="userInfoService" class="com.gxa.bj.service.UserInfoService">
<property name="userMapper" ref="userMapper"></property>
</bean>
<aop:config>
<aop:aspect id="recordTime" ref="recordTimebean">
<aop:pointcut expression="execution(* com.gxa.bj.service.*.*(..))" id="pointcut"/>
<!-- 要织入增强的方法的匹配 -->
<aop:around method="around" pointcut-ref="pointcut"/>
</aop:aspect>
</aop:config>