Spring XML配置aspectj注入bean是ClassNotFoundException

时间:2018-08-06 01:59:23

标签: java spring

在学习Spring in action 4.5的章节时,遇到了困难,我使用xml配置Spring AspectJ,但始终报告错误:由:java.lang.ClassNotFoundException引起,请帮助我,谢谢。这是我的xml :

<bean id="performance" class="com.springinaction.aop.concert.PerformanceImpl"/>

    <bean id="criticismEngine" class="com.springinaction.aop.concert.CriticismEngineImpl">
        <property name="criticismPool">
            <list>
                <value>Worst performance ever!</value>
                <value>A must see show!</value>
                <value>I laughed,I cried, then I realized i was at the wrong show</value>
            </list>
        </property>
    </bean>

    <bean class="com.springinaction.aop.concert.CriticAspect" factory-method="aspectOf">
        <property name="criticismEngine" ref="criticismEngine"/>
    </bean>
</beans>

这也是我的方面

public aspect CriticAspect {

    private CriticismEngine criticismEngine;

    public CriticAspect() {
    }

    pointcut performance():execution(* perform(..));

    after()returning:performance(){
        System.out.println(criticismEngine.getCriticism());
    }

    public void setCriticismEngine(CriticismEngine criticismEngine) {
        this.criticismEngine = criticismEngine;
    }
}

但是为什么抛出异常:

    Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@35f983a6] to prepare test instance [com.springinaction.soundsystem.PerformanceTest@18a70f16]
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.springinaction.aop.concert.CriticAspect] for bean with name 'com.springinaction.aop.concert.CriticAspect#0' defined in class path resource [spring/criticism-engine.xml]; nested exception is java.lang.ClassNotFoundException: com.springinaction.aop.concert.CriticAspect
Caused by: java.lang.ClassNotFoundException: com.springinaction.aop.concert.CriticAspect
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
java.lang.IllegalStateException: Failed to load ApplicationContext

    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
    at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.springinaction.aop.concert.CriticAspect] for bean with name 'com.springinaction.aop.concert.CriticAspect#0' defined in class path resource [spring/criticism-engine.xml]; nested exception is java.lang.ClassNotFoundException: com.springinaction.aop.concert.CriticAspect
    at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1377)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:683)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:639)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:608)
Caused by: java.lang.ClassNotFoundException: com.springinaction.aop.concert.CriticAspect
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)

0 个答案:

没有答案