Spring 3@Aspect使用问题
package com.spring3.chrp07.aspectj.aspectj;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
@Aspect
public class PreGreetingAspect {
@Before("execution(* greetTo(..))")
public void beforeGreeting(){
System.out.println("How are you!");
}
}
package com.spring3.chrp07.aspectj.aspectj;
import org.springframework.aop.aspectj.annotation.AspectJProxyFactory;
import com.spring3.chrp06.advice.NaiveWaiter;
import com.spring3.chrp06.advice.Waiter;
public class AspectJProxyTest {
public static void main(String[] args) {
Waiter target = new NaiveWaiter();
AspectJProxyFactory factory = new AspectJProxyFactory();
factory.setTarget(target);
factory.addAspect(PreGreetingAspect.class);
Waiter proxy = factory.getProxy();
proxy.greetTo("JOHN");
proxy.serveTo("JOHN");
}
}
以上是我做的一个小demo,greetTo和serveTo均是打印文字。
看似配置没有错,但是报了类初始化相关的错误,找不到原因,求高人帮看一下
Exception in thread "main" java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException
at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getPointcut(ReflectiveAspectJAdvisorFactory.java:187)
at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisor(ReflectiveAspectJAdvisorFactory.java:172)
at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.getAdvisors(ReflectiveAspectJAdvisorFactory.java:105)
at org.springframework.aop.aspectj.annotation.AspectJProxyFactory.addAdvisorsFromAspectInstanceFactory(AspectJProxyFactory.java:121)
at org.springframework.aop.aspectj.annotation.AspectJProxyFactory.addAspect(AspectJProxyFactory.java:111)
at com.spring3.chrp07.aspectj.aspectj.AspectJProxyTest.main(AspectJProxyTest.java:15)
Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.BCException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 6 more
------解决方案--------------------没有aspectjweaver.jar