三种顾问,增强及Aspectj 的详解

 

///通知

 

此处的是实现类作为方法的增强

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
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.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<!--添加AOP命名空间在AOP这个空间下-->

<!--1.目标对象--><!--2.要匹配的通知-->
<bean id="someservice" class="cn.spring09aop01.Someservice"></bean>
<bean id="beforeAdvice" class="cn.spring09aop01.MyBeforeAdvice"></bean>

<!--3经典 aop的 代理工厂bean-->
<bean id="proxyService" class="org.springframework.aop.framework.ProxyFactoryBean">
<!--配置需要增强的目标对象-->
<property name="target" ref="someservice"></property>
<!--拦截的名称类型是字符串类型的 value=“beforeAdvice” 做怎么样的增强-->
<property name="interceptorNames" value="beforeAdvice"></property>
</bean>


</beans>

<!--02.增强:顾问正则匹配切入点-->
<bean id="beforeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="beforeAdvice"></property>
<property name="pattern" value=".*d.*"></property>
</bean>

BeanName
<!--aop-->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">

<property name="beanNames" value="someservice"></property>
<property name="interceptorNames" value="beforeAdvice"></property>
</bean>

<!--02.增强:顾问正则匹配切入点-->
<bean id="beforeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="beforeAdvice"></property>
<property name="pattern" value=".*d.*"></property>
</bean>
在Xml中配置一个这个就是默认的自动代理自动代理生成器
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>

 

 

@Test
public void ddaq() {
//正则表达式匹配方法切入点
ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext0.xml");
ISomeService service = (ISomeService) ctx.getBean("proxyService");

service.doSome();


}
这是我们昨天学习的,我也不知道怎么说。。。。
posted @ 2017-08-01 15:29  liuzhe01  阅读(265)  评论(0编辑  收藏  举报