-
背景:学习切面,测试前置通知功能,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错误——Spring AOP——org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException
Easter79
2021-10-12
1164 0 0
点赞
收藏
评论区
加载中...