为了账号安全,请及时绑定邮箱和手机立即绑定

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


正在回答

8 回答

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

1 回复 有任何疑惑可以回复我~

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>


1 回复 有任何疑惑可以回复我~
#1

Elske63

感谢!
2019-11-03 回复 有任何疑惑可以回复我~

缺少aspectjweaver-1.8.10.jar,这个包

1 回复 有任何疑惑可以回复我~

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


0 回复 有任何疑惑可以回复我~

看最后一句  缺少包aspectjweaver

2 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

配置文件

<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>


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Spring入门篇
  • 参与学习       268787    人
  • 解答问题       963    个

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

进入课程

spring aop 配置问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信