1.名称匹配方法切入点顾问

接口:ISomeService

public interface ISomeService {
public void doSome(); public void doSecont(); }

public class MyBeforeAdvise implements MethodBeforeAdvice {

    public void before(Method method, Object[] objects, Object o) throws Throwable {
System.out.println("==========log=========="); }
}
public class SomeService implements ISomeService {
//核心业务
public void doSome() {
System.out.println("拜托别让他一番努力换来是奢求!");
} public void doSecont() {
System.out.println("=================Secont================"); } }

配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!--前置通知 名称匹配方法切入点顾问-->
<!--.目标对象-->
<bean id="someService" class="cn.happy.spring08aop_Advice.SomeService"></bean>
<!--.前置增强(通知)-->
<bean id="beforeAdvice" class="cn.happy.spring08aop_Advice.MyBeforeAdvise"></bean> <!--.前置增强(顾问)-->
<bean id="beforeAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
<property name="advice" ref="beforeAdvice"></property>
<property name="mappedNames" value="beforeAdvisor"></property>
</bean>
<!--.aop-->
<bean id="proxyService" class="org.springframework.aop.framework.ProxyFactoryBean">
<!--配置需要增强的目标对象-->
<property name="target" ref="someService"></property> <property name="interceptorNames" value="beforeAdvice"></property>
<property name="proxyTargetClass" value="true"></property>
</bean>
</beans>

单测

//1.前置通知 名称匹配方法切入点顾问
@Test
public void test01(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext05_aop05_Advice.xml");
ISomeService service = (ISomeService) ctx.getBean("proxyService");
service.doSome();
service.doSecont();
}

2.正则表达式 匹配方法切入点顾问

接口:ISomeService

public interface ISomeService {
public void doSome(); public void doSecont();
}

public class MyBeforeAdvise implements MethodBeforeAdvice {

    public void before(Method method, Object[] objects, Object o) throws Throwable {
System.out.println("==========log=========="); }
}
public class SomeService implements ISomeService {
//核心业务
public void doSome() {
System.out.println("拜托别让他一番努力换来是奢求!");
} public void doSecont() {
System.out.println("++===================Secont====================++"); } }

配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!--正则表达式 匹配方法切入点顾问-->
<!--.目标对象-->
<bean id="someService" class="cn.happy.spring09aop_AdviceZenz.SomeService"></bean>
<!--.前置增强(通知)-->
<bean id="beforeAdvice" class="cn.happy.spring09aop_AdviceZenz.MyBeforeAdvise"></bean> <!--.前置增强(顾问)-->
<bean id="beforeAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice" ref="beforeAdvice"></property>
<property name="pattern" value=".*d.*"></property>
</bean>
<!--.aop-->
<bean id="proxyService" class="org.springframework.aop.framework.ProxyFactoryBean">
<!--配置需要增强的目标对象-->
<property name="target" ref="someService"></property> <property name="interceptorNames" value="beforeAdvisor"></property> </bean>
</beans>

单测

 //2.正则表达式 匹配方法切入点顾问
@Test
public void test02(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext06_aop06_Zenz.xml");
ISomeService service = (ISomeService) ctx.getBean("proxyService");
service.doSome();
service.doSecont();
}

Spring 顾问的更多相关文章

  1. Spring顾问、IOC注解和注解增强

    一.顾问 通知的一种表现方式(顾问包装通知/增强) Advisor: 名称匹配方法: NameMecthMethodPointcutAdvisor 1.定义了一个业务类 package cn.spri ...

  2. Spring——顾问封装通知

    通知(advice)是Spring中的一种比较简单的切面,只能将切面织入到目标类的所有方法中,而无法对指定方法进行增强 顾问(advisor)是Spring提供的另外一种切面,可以织入到指定的方法中  ...

  3. spring顾问包装通知

    前边说到了顾问就是通知,没有实践,这里就实践一下,证明一下. 虽然可以说顾问就是通知,但是他们还是有的一定的区别的,通知是将目标类中所有的方法都进行的增强,而顾问却可以指定到特定的方法上,也就是说顾问 ...

  4. spring增强

    1.前置增强 接口:ISomeService public interface ISomeService { public void doSome(); } 类 public class MyBefo ...

  5. Spring 通知(Advice)和顾问(Advisor)

    AOP ( Aspect  Oriented Programming  面向切面编程)  在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...

  6. Spring中的通知(Advice)和顾问(Advisor)

    在Spring中,目前我学习了几种增强的方式,和大家分享一下 之前的话: 1.AOP  (Aspect  Oriented Programming  面向切面编程) 在软件业,AOP为Aspect O ...

  7. SSM-Spring-12:Spring中NameMatchMethodPointcutAdvisor名称匹配方法切入点顾问

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- advice 是通知advisor 是顾问 顾问(Advisor) 通知Advice是Spring提供的一种切 ...

  8. Spring 通知和顾问进行增强

    使用顾问增加前置增强和后置增强 <bean id="1" class="目标对象"></bean> <bean id=" ...

  9. Spring笔记07(Spring AOP的通知advice和顾问advisor)

    1.Spring AOP的通知advice 01.接口代码: package cn.pb.dao; public interface UserDao { //主业务 String add(); //主 ...

随机推荐

  1. 取分组TOPN好理解案例

  2. P3515 [POI2011]Lightning Conductor[决策单调性优化]

    给定一序列,求对于每一个$a_i$的最小非负整数$p_i$,使得$\forall j \neq i $有$ p_i>=a_j-a_i+ \sqrt{|i-j|}$. 绝对值很烦 ,先分左右情况单 ...

  3. Codeforces 758A. Holiday Of Equality 贪心

    题目大意: 给定一个长为\(n\)序列,每次操作在一个数上+1,求最小的操作次数使所有的数大小相同. 题解: 对这种题无话可说 #include <cstdio> #include < ...

  4. dubbo的扩展点重构

    可扩展设计是框架要重点考虑的设计,因为它直接影响到框架的稳定性和功能的扩展,Dubbo扩展点重构.它在扩展性设计上踩过的坑,值得框架设计者借鉴学习. 第一步,微核心,插件式,平等对待第三方 即然要扩展 ...

  5. android和iOS平台的崩溃捕获和收集

    转自:http://www.cnblogs.com/lancidie/archive/2013/04/13/3019349.html 通过崩溃捕获和收集,可以收集到已发布应用(游戏)的异常,以便开发人 ...

  6. Poco 编译mysql

    POCO mysql需要自己添加connecter的header和lib MySQL Client: For the MySQL connector, the MySQL client librari ...

  7. CF-811B

    B. Vladik and Complicated Book time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  8. 星级评分--封装成jquery插件

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. HDU - 1535 Invitation Cards 前向星SPFA

    Invitation Cards In the age of television, not many people attend theater performances. Antique Come ...

  10. Linear Algebra - Matrix

    1. 矩阵 定义:有 \(m*n\) 个数 \(a_{ij}(i=1,2,\cdots,m; j=1,2,\cdots,n)\) 排成的 \(m\) 行 \(n\) 列的数表 \[ \begin{Bm ...