我按照Spring in action书上的例子做切面的自动代理@Aspect
public class Audience { public Audience(){
}

@Pointcut("execution(* *.perform(..))")//匹配任意类的perform()方法
public void performance(){
}

@Before("performance()")
public void takeSeat(){
System.out.println("takeSeat");
}

@Before("performance()")
public void turnoffCellPhones(){
System.out.println("turnoffCellPhones");
}

@AfterReturning("performance()")
public void applaud(){
System.out.println("applaud");
}

@AfterThrowing("performance()")
public void demandRefund(){
System.out.println("demandRefund");
}
}配置文件是
<!-- 创建自动代理 -->
<aop:aspectj-autoproxy />

<bean id="audience" class="aoptest.Audience"/>

<!-- 目标Bean -->
<bean id="duke" class="aoptest.Duke"/>如果正确的话,应该在调用任何对象的perform()方法的时候会调用切面里的那些方法啊
可是我在调用duke这个bean里的perform()方法时没有
而且我仔细看了书上的内容,好像就只有这俩步啊
难道我漏了哪里?

解决方案 »

  1.   

    1.配置文件<?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">
        <aop:aspectj-autoproxy proxy-target-class="true"/>
        <bean id="audience" class="aoptest.Audience"/>     <!-- 目标Bean --> 
        <bean id="duke" class="aoptest.Duke"/> 
    </beans>试一下这样配置
      

  2.   

    这个看看尚学堂的spring视频带就都清楚了