Spring错误——Spring AOP——org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

  • 背景:学习切面,测试前置通知功能,xml配置如下

    1<?xml version="1.0" encoding="UTF-8"?> 2<beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:aop="http://www.springframework.org/schema/aop" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context.xsd 10 http://www.springframework.org/schema/aop 11 http://www.springframework.org/schema/aop/spring-aop.xsd" > 12 13 <bean id="ikAspect" class="com.jing.spring.aop.IKAspect"></bean> 14 <bean id="ikAspectBiz" class="com.jing.spring.aop.IKAspectBiz"></bean> 15 16 <aop:config> 17 <aop:aspect id="ikAspectAop" ref="ikAspect"> 18 <aop:pointcut id="ikPoint" expression="execution(* com.jing.spring.aop.IKAspectBiz.*(..))"></aop:pointcut> 19 <aop:before method="aspectBefore" pointcut-ref="ikPoint"></aop:before> 20 </aop:aspect> 21 </aop:config> 22</beans>
  • 报错:org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

    1Caused by: java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException 2 at java.lang.Class.getDeclaredConstructors0(Native Method) 3 at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) 4 at java.lang.Class.getConstructor0(Class.java:3075) 5 at java.lang.Class.getDeclaredConstructor(Class.java:2178) 6 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80) ... 66 more Caused by: java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 71 more
  • 原因:Spring AOP 虽然有自己的AOP功能,但是它是依赖AspectJ来实现的。使用maven搭建的项目pom.xml中,没有引入aspectjweaver包。

  • 解决办法:在pom.xml中引入aspectjweaver包。

    1<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --> 2 <dependency> 3 <groupId>org.aspectj</groupId> 4 <artifactId>aspectjweaver</artifactId> 5 <version>1.9.2</version> 6 </dependency>
  • 测试成功

  • Next

点赞
收藏

评论区

加载中...

相关推荐

spring集成JMS activeMQ 头文件

<beansxmlns"http://www.springframework.org/schema/beans"xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance"xmlns:amq"http://activemq.apache.org/schema/core"

Spring MVC 配置文件dispatcher

1.<?xmlversion\"1.0"encoding\"UTF8"?2.<beansxmlns\"http://www.springframework.org/schema/beans"3.xmlns:mvc\"http://www.springframework.org/schema/mvc"4.xml

Spring 使用注解方式进行事务管理

使用步骤:步骤一、在spring配置文件中引入<tx:命名空间<beansxmlns"http://www.springframework.org/schema/beans" xmlns:xsi"http://www.w3.org/2001/XMLSchemainstance" xmlns:tx"http

Dubbo通过注解实现RPC调用

启动Dubbo服务有2个方式,1是通过xml配置,2是通过注解来实现,这点和Spring相似。采用XML配置如下:<?xmlversion"1.0"encoding"UTF8"?<beansxmlns"http://www.springframework.org/schema/beans"

Spring中hibernateTemplate的使用

1.<?xmlversion\"1.0"encoding\"UTF8"?2.<beansxmlns\"http://www.springframework.org/schema/beans"3.xmlns:xsi\"http://www.w3.org/2001/XMLSchemainstance"xmlns:con

Spring Task 定时任务

推荐使用基于配置XML的形式!!!     //首先要定义schema 空间     <?xml version"1.0" encoding"UTF8"?          <beans xmlns"http://www.springframework.org/schema/beans"