<?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.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="sr" class="com.springmodel.Shiren" />
<bean id="qs" class="com.springmodel.Qishi">
</bean>

    <aop:config>
<aop:aspect ref="sr" >
<aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian(*))" />
<aop:before method="singBefore" pointcut-ref="qeMethod"/>
<aop:after method="singAlter" pointcut-ref="qeMethod"/>
</aop:aspect>
</aop:config>
</beans>
package com.springmodel;public class Shiren {
public void singBefore(){
System.out.println("探险之前sing");
}
public void singAlter(){
System.out.println("探险之后sing");
}
}
程序能够运行成功过,但是这2条语句 <aop:before method="singBefore" pointcut-ref="qeMethod"/>
<aop:after method="singAlter" pointcut-ref="qeMethod"/>运行没有效果

解决方案 »

  1.   


    有点不是很懂,但是我Qishi里面是实现了1个接口
      

  2.   

    (* com.springmodel.Qishi.tanXian(*)) 改成 (* com.springmodel.Qishi.tanXian(..))呢
      

  3.   


    tanXian()里面只能有*,用..会抛异常
      

  4.   

    (* com.springmodel.Qishi.*(..)) 
      

  5.   


    代码没报错,反而运行成功,只不过这2条语句没长生任何效果
    <aop:before method="singBefore" pointcut-ref="qeMethod"/>
    <aop:after method="singAlter" pointcut-ref="qeMethod"/>
      

  6.   

    com.springmodel.Qishi这个是个Class吧,你在造型的时候需要用Qishi实现的那个接口。
    如果直接造型成class会报错:
    Exception in thread "main" java.lang.ClassCastException:
      

  7.   


    public static void main(String[] args) throws Exception {
    ApplicationContext act = new ClassPathXmlApplicationContext("applicationContext.xml");
    // 这样写会报错
    // LogTestServiceImpl s = (LogTestServiceImpl)act.getBean("LogTestService");
    LogTestService s = (LogTestService) act.getBean("LogTestService");
    s.say();
    }
      

  8.   


    没作用,现在关键的是这2条语句配置了和没配置一样
    而且我把它改成TanXian tx=(TanXian)apc.getBean("qs");
    也没左右  TanXian(为接口) Qishi实现了它的方法
    <aop:before method="singBefore" pointcut-ref="qeMethod"/>
    <aop:after method="singAlter" pointcut-ref="qeMethod"/>
      

  9.   

    终于发现咯......
     <aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian(*))" />
    这句造成的,用*号就会这样,测试过了。换成..或者什么都不要试试吧
      

  10.   

    晕,怎么看不见哦。
     <aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian(*))" />
    这个导致的,改成
     <aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian(..))" />或者
     <aop:pointcut id="qeMethod" expression="execution(* com.springmodel.Qishi.tanXian())" />试试吧