女雅乱 2009-08-10 19:53
浏览 263
已采纳

为什么spring2.5 aop没有执行切入前后的方法呢?

我在学习spring in action 这本书的aop的例子时,为什么我编译没有报错,但是却没有执行我切入前后的方法?

xml配置代码如下:

<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" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-2.5.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> 

   <bean id= "quest" class ="com.knight.HolyGrailQuest">
   </bean>
   <bean id = "knight" class = "com.knight.KnightOfTheRoundTable">
      <constructor-arg value='sotomi' />
      <property name='quest' ref='quest'></property>
   </bean>

   <bean id = "minstrel" class = "com.knight.Minstrel"></bean>
   <aop:config>
      <aop:aspect ref = 'minstrel' >
          <aop:pointcut id='questPointCut' expression='execution(* *.embarkOnQuest(..)) and target(bean)' />
          <aop:before method='singBefore' pointcut-ref='questPointCut' arg-names = 'bean' />
          <aop:after-returning method='singAfter' pointcut-ref='questPointCut' arg-names = 'bean' />
      </aop:aspect>
   </aop:config>
</beans>

 Minstrel类的方法如下:

public class Minstrel {

    private static final Logger Song =  Logger.getLogger(Minstrel.class);
    
    public void singBefore(Knight knight){
        Song.info("Knight is so brave!");
        System.out.println("**********************before");
    }
    
    public void singAfter(Knight knight){
        Song.info("Knight did quest the grail!");
    }
}

测试main函数:

public class Test {

   public static void main(String args[]){

       BeanFactory factory = new XmlBeanFactory(new FileSystemResource("bean.xml"));
       Knight knight = (Knight)factory.getBean("knight");
       knight.embarkOnQuest();

       
   }
}

 但是执行后没有打印结果,我哪里设置错误了么?

  • 写回答

1条回答 默认 最新

  • qbqopen 2009-08-12 13:46
    关注

    怀疑


    中的expression有误

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题