2、基于 XML配置文件的管理方式。
- 不配置切入点
81. <?xml version="1.0" encoding="UTF-8"?>
82. <beans xmlns="http://www.springframework.org/schema/beans"
83. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
84. xmlns:aop="http://www.springframework.org/schema/aop"
85. xsi:schemaLocation="http://www.springframework.org/schema/beans
86. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
87. http://www.springframework.org/schema/aop
88. http://www.springframework.org/schema/beans/spring-aop-3.0.xsd">
89. <aop:config>
90. <!-- 将 fourAdviceBean 转换成切面 Bean, 切面 Bean 的新名称为:fourAdviceAspect,指定该切面的优先级为2 -->
91. <aop:aspect id="fourAdviceAspect" ref="fourAdviceBean" order="2">
92. <!-- 定义个After增强处理,直接指定切入点表达式,以切面 Bean 中的 Release() 方法作为增强处理方法 -->
93. <aop:after pointcut="execution(* com.wicresoft.app.service.impl.*.*(..))" method="release" />
94.
95. <!-- 定义个Before增强处理,直接指定切入点表达式,以切面 Bean 中的 authority() 方法作为增强处理方法 -->
96. <aop:before pointcut="execution(* com.wicresoft.app.service.impl.*.*(..))" method="authority" />
97.
98. <!-- 定义个AfterReturning增强处理,直接指定切入点表达式,以切面 Bean 中的 log() 方法作为增强处理方法 -->
99. <aop:after-returning pointcut="execution(* com.wicresoft.app.service.impl.*.*(..))" method="log" />
100.
101. <!-- 定义个Around增强处理,直接指定切入点表达式,以切面 Bean 中的 processTx() 方法作为增强处理方法 -->
102. <aop:around pointcut="execution(* com.wicresoft.app.service.impl.*.*(..))" method="processTx" />
103.
104. </aop:aspect>
105. </aop:config>
106.
107. <!-- 省略各个Bean 的配置 -->
108. <!-- ... -->
109.
110. </beans>
配置切入点
111. <?xml version="1.0" encoding="UTF-8"?>
112. <beans xmlns="http://www.springframework.org/schema/beans"
113. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
114. xmlns:aop="http://www.springframework.org/schema/aop"
115. xsi:schemaLocation="http://www.springframework.org/schema/beans
116. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
117. http://www.springframework.org/schema/aop
118. http://www.springframework.org/schema/beans/spring-aop-3.0.xsd">
119. <aop:config>
120. <!-- 定义一个切入点,myPointcut,直接知道它对应的切入点表达式 -->
121. <aop:pointcut id="myPointcut" expression="execution(* com.wicresoft.app.service.impl.*.*(..))" method="release" />
122. <aop:aspect id="afterThrowingAdviceAspect" ref="afterThrowingAdviceBean" order="1">
123. <!-- 使用上面定于切入点定义增强处理 -->
124. <!-- 定义一个AfterThrowing 增强处理,指定切入点以切面 Bean 中的 doRecovertyActions() 方法作为增强处理方法 -->
125. <aop:after-throwing pointcut-ref="myPointcut" method="doRecovertyActions" throwing="ex" />
126. </aop:aspect>
127. </aop:config>
128.
129. <!-- 省略各个Bean 的配置 -->
130. <!-- ... -->
131.
132. </beans>
参考:http://blog.csdn.net/a906998248/article/details/7514969