和Spring1.X相比,Spring2.X使用AspectJ的語法來聲明AOP.本人也真在學習.
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">
聲明一個切面 id="隨便定義" ref="引用上面的bean(aa)"
<aop:pointcut id="businessService" expression = "execution(* springinaction.chapter01.knight.Tempimp.temp(..))" />
聲明一個切入點
<aop:around pointcut-ref="businessService" method="intercept"/>
通知
<aop:after pointcut-ref = "businessService" method ="temp"/>
聲明通知
</aop:aspect>
</aop:config>
</beans>
結果還是會調用temp()方法.打印出jsong。
現在還在繼續學些spring2.X。希望大家多多指教.有什么問題,大家互相學習