2012-09-29 29 views
1

我想在Spring 3.1.5上使用AOP實現日誌記錄。但在運行時我收到以下異常使用Spring 3.1.2實現@AspectJ時面臨的問題

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.manh.fm.bid.ejb.BidMgr' defined in class path resource [appCtx-fm.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.adapter.UnknownAdviceTypeException: Advice object [null] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor] 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:110) 
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280) 
    ... 89 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.manh.fm.bid.ejb.BidMgr' defined in class path resource [appCtx-fm.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.adapter.UnknownAdviceTypeException: Advice object [null] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) 
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:105) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) 
    ... 91 more 
Caused by: org.springframework.aop.framework.adapter.UnknownAdviceTypeException: Advice object [null] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor] 
    at org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry.getInterceptors(DefaultAdvisorAdapterRegistry.java:88) 
    at org.springframework.aop.framework.DefaultAdvisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(DefaultAdvisorChainFactory.java:61) 
    at org.springframework.aop.framework.AdvisedSupport.getInterceptorsAndDynamicInterceptionAdvice(AdvisedSupport.java:482) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:188) 
    at $Proxy136.getTransactionAttribute(Unknown Source) 
    at org.springframework.transaction.interceptor.TransactionAttributeSourcePointcut.matches(TransactionAttributeSourcePointcut.java:36) 
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:227) 
    at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:264) 
    at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:296) 
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:117) 
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:87) 
    at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68) 
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359) 
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1461) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
    ... 106 more 

這裏是我的方面類的細節:

@Aspect 
public class LoggingAspect { 


    @Before("allGetters()") 
    public void LoggingAdvice(){ 

     System.out.println("AspectJ Logging"); 
    } 
    @Pointcut("execution(* com.manh.fm.kjb.MgrBean.processMyAction(..))") 
    public void allGetters(){} 

} 

這裏是我的Spring上下文文件的細節

<?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" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd 
      http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> 

<aop:aspectj-autoproxy/> 
<bean 
     id="com.manh.fm.bid.ejb.BidMgr" 
     autowire="default" 
     class="com.manh.fm.bid.ejb.BidMgrBean" 
     dependency-check="default" 
     lazy-init="default" 
     > 
    </bean> 
<bean id="loggingAspect" 
      class="com.manh.fm.aspectj.logger.LoggingAspect"/> 
</beans> 

我使用的AspectJ相關jar與相關的彈簧罐一起使用的是 aopalliance-1.0,asm-all-3.0,aspectjrt-1.6.10,aspectjweaver,cglib-nodep- 2.2.2

夥計們我真的被這個困住了,我也是Aop的新手,請幫助我這個!

回答

0

我也有類似的問題,幾日回來,org.springframework.beans.factory.BeanCreationException:錯誤創建豆

對我來說,這是老罈子My issue

你可以嘗試的一個問題採用最新的罐子來運行你的應用程序:

aopalliance-1.0.jar 
asm-3.3.1.jar 
aspectj-1.7.1.jar 
aspectjrt-1.7.0.jar 
aspectjweaver-1.7.0.jar 
cglib-2.2.2.jar 
1

嘗試實行「org.aopalliance.intercept.MethodInterceptor」,它是一個的「org.aopalliance.aop.Advice這個」子接口「,由急診室的建議ROR。