1

我正在尝试在 Spring 3.1.5 上使用 AOP 实现日志记录。但在运行时我得到以下异常

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(){}

}

这是我的弹簧上下文文件的详细信息

 <?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 以及相关 spring jar 是 aopalliance-1.0,asm-all-3.0,aspectjrt-1.6.10,aspectjweaver,cglib-nodep-2.2.2

伙计们,我真的很困惑,而且我也是 Aop 的新手,请帮我解决这个问题!

4

2 回答 2

1

尝试实现“org.aopalliance.intercept.MethodInterceptor”,它是“org.aopalliance.aop.Advice”的“子接口”,如错误所示。

于 2013-11-15T15:57:08.740 回答
0

几天前我遇到了类似的问题,org.springframework.beans.factory.BeanCreationException: Error creating bean

就我而言,这是旧罐子的问题 我的问题

您可以尝试使用最新的 jar 运行您的应用程序吗:

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
于 2012-12-19T19:25:30.093 回答