AOP配置方式

一:基于XML配置
<!--目标对象 -->
<bean id="AOPservice" class="com.study.spring.service.impl.AOPServiceImpl"/>
<!-- advice通知 -->
<bean id="adviceMessage" class="com.study.spring.aop.advice.Advicer"/>
<bean id="perfAdvice" class="com.study.spring.aop.advice.PerfAdvicer"/>
<!-- 切入点adviser -->
<bean id="adviser" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="adviceMessage"/>
<property name="pattern" value="com.study.spring.service.impl.AOPServiceImpl.print"></property>
</bean>
<bean id="perfAdviser" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="perfAdvice"/>
<property name="pattern" value="com.study.spring.service.impl.AOPServiceImpl.*(..)"></property>
</bean>
<!-- 代理对象 返回实例是目标对象 target属性指定的AOPservice对象-->
<bean id="proxyService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="AOPservice"/>
</property>
<!--源码内固定的属性private String[] interceptorNames; -->
<property name="interceptorNames">
<list>
<value>adviser</value>
<value>perfAdviser</value>
</list>
</property>
</bean>
二:基于XML配置
<bean id="perfAdviser" class="com.study.spring.aop.advice.PerfAdvicer2" />
<aop:config proxy-target-class="true">
<aop:aspect ref="perfAdviser">
<aop:pointcut id="methodPoint" expression="execution(* com.study.spring.service.impl.AOPServiceImpl.*(..)) "/>
<!--在该切入点使用自定义拦截器-->
<aop:before pointcut-ref="methodPoint" method="before"/>
<aop:around pointcut-ref="methodPoint" method="around"/>
<aop:after pointcut-ref="methodPoint" method="after"/>
<aop:after-returning pointcut-ref="methodPoint" method="afterRet"/>
<aop:after-throwing pointcut-ref="methodPoint" method="afterError"/>
</aop:aspect>
</aop:config>
三:基于注解配置
<bean id="AOPservice" class="com.study.spring.service.impl.AOPServiceImpl"/>
<bean id="perfAdvice" class="com.study.spring.aop.advice.PerfAdvicer3"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值