日期:2014-05-17  浏览次数:20843 次

【求助】菜鸟Spring配置问题
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
at 
...省略

程序之前没问题的,后来我加了这个类就出错了

package com.zhg.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogInterceptor {
@Pointcut("execution(public * com.zhg.service..*.add(..))")
public void MyMethod() {}

@Before("MyMethod()")
public void befor() {
System.out.println("方法开始之前!");
}

@Around("execution(public * com.zhg.service..*.add(..))")
public void AroundMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("方法开始...");
pjp.proceed();
System.out.println("方法结束!");
}

}

这是配置文件

<?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.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd 
 http://www.springframework.org/schema/aop 
 http://www.springframework.org/schema/aop/spring-aop.xsd"> 
         
<context:annotation-config />
<context:component-scan base-package="com.zhg" />
<aop:aspectj-autoproxy />

</beans>