XMl的配置后执行顺序是
around之前通知:
before通知:
after通知:
around之后通知:
配置如下:<!--ADVICE-->
<bean id="theAspectAdvice" class="xmlAOP.TheAspect" />
<!--CLASS-->
<bean id="beanTarget" class="xmlAOP.NaiveWaiter" />
<!-- 配置代理,制定目标类,和使用的切面-->
<bean id="factoryBean" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>xmlAOP.Waiter</value>
</property>
<property name="target">
<ref local="beanTarget" />
</property>
<property name="interceptorNames">
<list>
<value>theAspect</value>
</list>
</property>
</bean>
<!--ADVISOR-->
<!--Note: An advisor assembles pointcut and advice-->
<bean id="theAspect" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="theAspectAdvice" />
</property>
<property name="pattern">
<value>
xmlAOP\.Waiter\.greetTo
</value>
</property>
<!--
<property name="proxyTargetClass" value="false" />
-->
</bean>
AsepctJAOP配置后执行的顺序是:
before通知:
around之前通知:
after通知:
around之后通知:配置如下: <bean id="TheAspect" class="aspectJAOP.TheAspect" />
<bean id="TheAspect2" class="aspectJAOP.TheAspect2" />
<bean id="Waiter" class="aspectJAOP.NaiveWaiter" /> <!-- 非动态代理,需要配置切面 -->
<aop:config ><!-- proxy-target-class="true" -->
<aop:aspect id="aspectTheAspect2" ref="TheAspect2">
<!--配置com.spring.service包下所有类或接口的所有方法-->
<aop:pointcut id="businessService"
expression="within(aspectJAOP.*Waiter)" />
<!--
其他几种配置
execution(* aspectJAOP.Waiter.*(..))
expression="within(aspectJAOP.*Waiter)"
expression="target(aspectJAOP.Waiter)" 只有target可以指定接口或接口的实现类,within 的指定必须是实现类。即不能这样:within(aspectJAOP.Wait*)用抽象接口名
-->
<aop:before pointcut-ref="businessService" method="doBefore"/>
<aop:after pointcut-ref="businessService" method="doAfter"/>
<aop:around pointcut-ref="businessService" method="doAround"/>
<aop:after-throwing pointcut-ref="businessService" method="doThrowing" throwing="ex"/>
</aop:aspect>
</aop:config>
直接写Java代码不用配置文件的执行顺序是:
before通知:
around之前通知:
around之后通知:
after通知:直接写的Java代码如下:
AspectJProxyFactory factory = new AspectJProxyFactory();
Waiter target = new NaiveWaiter();
factory.setTarget(target);
factory.addAspect(TheAspect.class);
target = factory.getProxy();
target.greetTo("fc");
around之前通知:
before通知:
after通知:
around之后通知:
配置如下:<!--ADVICE-->
<bean id="theAspectAdvice" class="xmlAOP.TheAspect" />
<!--CLASS-->
<bean id="beanTarget" class="xmlAOP.NaiveWaiter" />
<!-- 配置代理,制定目标类,和使用的切面-->
<bean id="factoryBean" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>xmlAOP.Waiter</value>
</property>
<property name="target">
<ref local="beanTarget" />
</property>
<property name="interceptorNames">
<list>
<value>theAspect</value>
</list>
</property>
</bean>
<!--ADVISOR-->
<!--Note: An advisor assembles pointcut and advice-->
<bean id="theAspect" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="theAspectAdvice" />
</property>
<property name="pattern">
<value>
xmlAOP\.Waiter\.greetTo
</value>
</property>
<!--
<property name="proxyTargetClass" value="false" />
-->
</bean>
AsepctJAOP配置后执行的顺序是:
before通知:
around之前通知:
after通知:
around之后通知:配置如下: <bean id="TheAspect" class="aspectJAOP.TheAspect" />
<bean id="TheAspect2" class="aspectJAOP.TheAspect2" />
<bean id="Waiter" class="aspectJAOP.NaiveWaiter" /> <!-- 非动态代理,需要配置切面 -->
<aop:config ><!-- proxy-target-class="true" -->
<aop:aspect id="aspectTheAspect2" ref="TheAspect2">
<!--配置com.spring.service包下所有类或接口的所有方法-->
<aop:pointcut id="businessService"
expression="within(aspectJAOP.*Waiter)" />
<!--
其他几种配置
execution(* aspectJAOP.Waiter.*(..))
expression="within(aspectJAOP.*Waiter)"
expression="target(aspectJAOP.Waiter)" 只有target可以指定接口或接口的实现类,within 的指定必须是实现类。即不能这样:within(aspectJAOP.Wait*)用抽象接口名
-->
<aop:before pointcut-ref="businessService" method="doBefore"/>
<aop:after pointcut-ref="businessService" method="doAfter"/>
<aop:around pointcut-ref="businessService" method="doAround"/>
<aop:after-throwing pointcut-ref="businessService" method="doThrowing" throwing="ex"/>
</aop:aspect>
</aop:config>
直接写Java代码不用配置文件的执行顺序是:
before通知:
around之前通知:
around之后通知:
after通知:直接写的Java代码如下:
AspectJProxyFactory factory = new AspectJProxyFactory();
Waiter target = new NaiveWaiter();
factory.setTarget(target);
factory.addAspect(TheAspect.class);
target = factory.getProxy();
target.greetTo("fc");
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货