日期:2014-05-20  浏览次数:21078 次

---------------->Spring 中使用Before advice报了一堆错<-----------

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator':

Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class

[org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested exception is

java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor


就是这样写的:
Java code

package org.spring.test;

import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class Log {
    
    @Before("execution(public void org.spring.test.UserDAOImpl.save(org.spring.test.User))")
    public void myLog() {
        System.out.println("You can do sth before this!!!");
    }
}




------解决方案--------------------
spring的aop是符合aop规范的,需要应用aopalliance.jar这个包,你可能没有这个包
------解决方案--------------------
请根据错误信息查错:
java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor
------解决方案--------------------
你注入的userDAO,不是org.spring.test.UserDAOImpl类,看看你的spring配置文件userDAO的类是什么。