在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ spring xml 添加aop config 后報錯

spring xml 添加aop config 后報錯

在學(xué)習(xí)Spring aop 時,最初能夠正常使用的xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
">


    <bean id="cat1" class="Animal.Cat">
    </bean>

    <bean id="rat1" class="Animal.Rat">
    </bean>

    <!--<aop:config>

        <aop:pointcut id="cat_mark" expression="execution(* Animal.Cat.mark(..))"  />

        <aop:aspect ref="rat1">
            <aop:before method="sleep" pointcut-ref="cat_mark" />
            <aop:after method="run" pointcut-ref="cat_mark" />
        </aop:aspect>

    </aop:config>-->

</beans>

當(dāng)我將上文注釋部分取消注釋后,運(yùn)行文件拋出非常長的異常,下面是其中一部分。


WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cat1' defined in class path resource [aop.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#304bb45b' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#304bb45b': Cannot resolve reference to bean 'cat_mark' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cat_mark': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cat1' defined in class path resource [aop.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#304bb45b' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#304bb45b': Cannot resolve reference to bean 'cat_mark' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cat_mark': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.aop.aspectj.AspectJExpressionPointcut]: No default constructor found; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

上述配置文件都是從教程上模仿下來的,我也對比過一些其他文件,就是無法找出錯誤。

這是Java文件


import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class aop {
    public static void main(String args[]){

        BeanFactory factory = new ClassPathXmlApplicationContext("aop.xml");

        Animal.Cat c1 =(Animal.Cat)factory.getBean("cat1");

        c1.mark();

    }
}

不是和理解為什么出錯,實在想不到哪里出錯了

回答
編輯回答
奧特蛋

檢查一下是否導(dǎo)入aspectjweaver.jar?

2018年3月20日 16:02