Spring 4.X 使用@AspectJ和Schema 报错
2017-11-01 22:01
302 查看
**XML配置**
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <context:annotation-config/> <aop:aspectj-autoproxy proxy-target-class="true"/> <aop:config proxy-target-class="true"> <aop:aspect ref="mymethod"> <aop:before pointcut="target(main.com.Greeting) " method="Cutin"/> <aop:after pointcut="target(main.com.Greeting)" method="Cutin2"/> </aop:aspect> </aop:config> <bean id="mymethod" class="main.com.Cut"/> <bean id="mytest" class="main.com.Greeting"/>
xml配置如上,IntelliJ IDEA 报如下错误,找不到aspectj需要的类包。
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.config.internalAutoProxyCreator': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:225) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:703) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at main.AopTest.main(AopTest.java:13) Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Around at org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.<clinit>(ReflectiveAspectJAdvisorFactory.java:77) at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.initBeanFactory(AnnotationAwareAspectJAutoProxyCreator.java:78) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.setBeanFactory(AbstractAdvisorAutoProxyCreator.java:60) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1647) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1615) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ... 11 more Caused by: java.lang.ClassNotFoundException: org.aspectj.lang.annotation.Around at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
<aop:before pointcut="target(main.com.Greeting) " method="Cutin"/> <aop:after pointcut="target(main.com.Greeting)" method="Cutin2"/> <aop:aspectj-autoproxy proxy-target-class="true"/>
把上面的注释后不报错。但是无法生成AOP代理添加aspectj.weaver 和 aspectj.tools 类包的依赖后,错误消失,编译通过
相关文章推荐
- Spring中的AOP——AspectJ的基本使用
- Spring4学习:基于@AspectJ和Schema的AOP
- Spring中Aspectj和Schema-based AOP混用引起的错误
- Spring中使用AspectJ指示器
- aspectj 使用spring AOP切面编程的时候报错:ReflectionWorld$ReflectionWorldException NoClassDefFoundError 的处理
- spring心得10--使用Aspectj进行AOP开发介绍及案例分析
- spring项目中使用Aspectj
- (spring-第19回【AOP基础篇】)基于AspectJ和Schema的AOP
- 8.4.2: Spring的AOP---使用AspectJ实现AOP
- spring 4.0 AOP (使用AspectJ的注解方式 的aop实现)简单实例
- Spring中使用AspectJ实现AOP
- spring之基于aspectj注解aop使用
- Spring使用AspectJ进行AOP的开发:注解方式
- spring 4.0 AOP (使用AspectJ的注解方式 的aop实现)简单实例
- 解决spring中使用声明事务java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable.
- Hibernate整合Spring后,如何使用SchemaExport生成数据库表
- 何时使用SpringAOP与aspectJ
- spring心得10--使用Aspectj进行AOP开发介绍及案例分析
- Spring使用AspectJ注解和XML配置实现AOP