问答详情
源自:5-5 Advice应用(下)

spring aop 配置问题

配置了aop就一直报错 大神求助

警告: Exception encountered during context initialization - cancelling refresh attempt

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aspectAspect' defined in URL [file:/E:/IdeaProjects/SpringBasic/out/production/SpringBasic/spring-aop-schema-advice.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)#21901ca8' 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)#21901ca8': Cannot resolve reference to bean 'pointcut' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pointcut': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException


Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#21901ca8' 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)#21901ca8': Cannot resolve reference to bean 'pointcut' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pointcut': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#21901ca8': Cannot resolve reference to bean 'pointcut' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pointcut': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pointcut': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException


提问者:芈峰 2015-11-22 13:42

个回答

  • 禇凌寒
    2017-08-12 09:36:00

    <!--添加aspectjweaver包 -->
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>1.8.5</version>
            </dependency>

  • 啊不得
    2017-05-20 17:25:11

    maven添加依赖

    <dependency>

    <groupId>org.aspectj</groupId>

    <artifactId>aspectjrt</artifactId>

    <version>1.6.12</version>

    </dependency>

    <dependency>

    <groupId>org.aspectj</groupId>

    <artifactId>aspectjweaver</artifactId>

    <version>1.6.12</version>

    </dependency>

    <dependency>

    <groupId>cglib</groupId>

    <artifactId>cglib</artifactId>

    <version>2.2</version>

    </dependency>


  • Jarly杰
    2017-03-07 09:39:46

    缺少aspectjweaver-1.8.10.jar,这个包

  • morethink
    2017-01-28 21:03:59

    aspectjweaver-1.8.10.jar

  • 慕妹8987190
    2016-08-19 16:56:57

    这个问题怎么解决谁知道啊??


  • YuanquanLu
    2016-01-16 11:36:18

    看最后一句  缺少包aspectjweaver

  • hanhanzhu
    2016-01-08 12:29:31

    应该切入点的expression切入点表达式写的不错execution(* com.peak.aop.schema.advice.biz.*.*(..)),表示执行biz包中的任意类中的任意方法,均可执行切面程序。

  • 芈峰
    2015-11-22 13:47:25

    配置文件

    <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"
                   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="aspectAspect" class="com.peak.aop.schema.advice.Aspect"></bean>
    <bean id="aspectBiz" class="com.peak.aop.schema.advice.biz.AspectBiz"></bean>
    
    <aop:config>
           <aop:pointcut id="pointcut" expression="execution(* com.peak.aop.schema.advice.biz.*(..))"/>
           <aop:aspect id="aspectAOP" ref="aspectAspect">
                  <aop:before method="work" pointcut-ref="pointcut"/>
           </aop:aspect>
    </aop:config>
    </beans>