和Spring1.X相比,Spring2.X使用AspectJ的語(yǔ)法來(lái)聲明AOP.本人也真在學(xué)習(xí).
package com.springinaction.chapter01.knight;
public class Tempimp implements Temp {
public void temp() {
System.out.println("jsong");
}
}
<?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"
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">
<bean id="aa" class="com.springinaction.chapter01.knight.Tempimp"/>
<aop:config>
<aop:aspect id ="logAspect" ref="aa">
聲明一個(gè)切面 id="隨便定義" ref="引用上面的bean(aa)"
<aop:pointcut id="businessService" expression = "execution(* springinaction.chapter01.knight.Tempimp.temp(..))" />
聲明一個(gè)切入點(diǎn)
<aop:around pointcut-ref="businessService" method="intercept"/>
通知
<aop:after pointcut-ref = "businessService" method ="temp"/>
聲明通知
</aop:aspect>
</aop:config>
</beans>
結(jié)果還是會(huì)調(diào)用temp()方法.打印出jsong。
現(xiàn)在還在繼續(xù)學(xué)些spring2.X。希望大家多多指教.有什么問(wèn)題,大家互相學(xué)習(xí)