AOP始终无法插入方法,求解。
package service;public class GoShopping {

public void buy(){
System.out.println("I buy a Sennheiser's HD555");
}

}package aop;import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;@Aspect
public class LogInterceptor {

@Before("execution(public void service.GoShopping.buy())") 
public void before(){
System.out.println("method star");
}
}<?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:context="http://www.springframework.org/schema/context"
       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/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">
<context:annotation-config/>
<aop:aspectj-autoproxy/>

<bean name="goShopping" class="service.GoShopping"></bean>
</beans>

解决方案 »

  1.   

    LogInterceptor  这个aspect要在配置文件中配一个bean
      

  2.   

    配置以后报异常Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'goShopping' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
      

  3.   

    LogInterceptor 的factory-method 要设置为:aspectof   好像是这样的
      

  4.   

    反正就是配置他的factory-method 属性。 自己google一下。。   另外楼主记得结贴;
      

  5.   

    具体方式就是<bean id="xxxxx"  class="xxxx"  factory-method="aspectOf" ></bean>然后就可以用了  记得在execution 里面用bean的id要对
      

  6.   

    楼主那个异常是少包,如果不是通过JAVA的接口代理,则需要CGLIB这个类继承代理包
      

  7.   

    我导入的包spring.jar
    commons.jar
    aspectjrt.jar
    aspectjweaver.jar还缺了什么吗?
      

  8.   

    哦,谢谢了,搞定。原来是少了cglib-nodep-2.1_3.jar