Spring學習 之 AOP (配置文件版)

配置文件

配置以外的文件可以參考 Spring學習 之 AOP

上記參考中的 所有注釋全部 去掉 ,且配置文件換成下記文件即可。

<?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:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	       http://www.springframework.org/schema/beans/spring-beans.xsd
		   http://www.springframework.org/schema/aop 
		   http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
		   http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-4.0.xsd">
	
	<bean id="artthemticCalculator" class="com.spring.apo.ArtthemticCalculatorImpl"></bean>
	<bean id="loggingAspect" class="com.spring.apo.LoggingAspect"></bean>
	<bean id="vlidationAspect" class="com.spring.apo.VlidationAspect"></bean>
	
	<aop:config>
		<aop:pointcut expression="execution(public int com.spring.apo.ArtthemticCalculator.*(..))" id="pointCut"/>
		<aop:aspect ref="loggingAspect" order="2">
			<aop:before method="beforeMethod" pointcut-ref="pointCut"/>
			<aop:after method="afterMethod" pointcut-ref="pointCut"/>
			<aop:after-throwing method="afterThrowing" pointcut-ref="pointCut" throwing="ex"/>
			<aop:after-returning method="afterReturning" pointcut-ref="pointCut" returning="result"/>
			<aop:around method="aroundMethod" pointcut-ref="pointCut"/>
			
		</aop:aspect>
		<aop:aspect ref="vlidationAspect" order="1">
			<aop:before method="beforeMethod" pointcut-ref="pointCut"/>
		</aop:aspect>
	
	</aop:config>

</beans>

 

發佈了21 篇原創文章 · 獲贊 0 · 訪問量 3432
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章