`
lochen514
  • 浏览: 9918 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
最近访客 更多访客>>
社区版块
存档分类
最新评论

配置spring aop

阅读更多
备注:execution(* com.fairy.service..*.*(..))是讲aop切面锁定到com.fairy.service这个包和子包下面的所有方法,事物切面仅仅限于这个包以及其子包下面。
在这里我提供几种配置方式,要想研究更深刻的配置规则各位自己去研究吧。

•任意公共方法的执行:
execution(public * *(..))
•任何一个以“set”开始的方法的执行:
execution(* set*(..))
•AccountService 接口的任意方法的执行:
execution(* com.fairy.service.AccountService.*(..))
•定义在service包里的任意方法的执行:
execution(* com.fairy.service.*.*(..))
•定义在service包或者子包里的任意方法的执行:
execution(* com.fairy.service..*.*(..))



<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
	
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >    
	        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>    
	        <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>    
	        <property name="username" value="scott"/>    
	        <property name="password" value="tiger"/>    
	</bean>
	
		 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">    
	        <property name="dataSource" ref="dataSource" />    
	     </bean>  
	
		<aop:config>
			<aop:advisor pointcut="execution(* com.fairy.service..*.*(..))" advice-ref="txAdvice"/>
		</aop:config>

		<tx:advice id="txAdvice" transaction-manager="txManager">    
			<tx:attributes>
				<tx:method propagation="REQUIRED" name="*" />
			</tx:attributes>
		</tx:advice>
	
	
</beans>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics