Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式

异常报错以及解决方法

一:简介

当我使用配置文件配置Bean时,导入如下图所示的八个jar包完全足够,但当我使用注解配置是,却出现了异常

Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第1张图片

异常信息如下

一月 14, 2019 11:46:35 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@63c12fb0: startup date [Mon Jan 14 23:46:35 CST 2019]; root of context hierarchy
一月 14, 2019 11:46:35 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [bean-user.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [bean-user.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:413)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:223)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:194)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:258)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:621)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:144)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:85)
	at com.lanou3g.controller.Test.main(Test.java:10)
Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
	at org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors(AnnotationConfigUtils.java:155)
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.registerComponents(ComponentScanBeanDefinitionParser.java:152)
	at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:91)
	at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:74)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1366)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1352)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:178)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:148)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:98)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
	... 14 more
Caused by: java.lang.ClassNotFoundException: org.springframework.aop.TargetSource
	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)
	... 25 more

三:解决方案

根据百度所搜索结果,发现缺少spring-aop-4.0.0.RELEASE.jar,于是我去下载了这个jar包,下载地址如下

四:下载jar包地址

http://repo.springsource.org/libs-release-local/org/springframework/spring/

打开这个网址,结果如下图所示,下载完后解压,得到文件夹

Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第2张图片
Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第3张图片
Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第4张图片
Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第5张图片

五:复制jar包并导入项目中

build path后,再次运行项目

Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第6张图片

六:发现再次报错

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.aop.scope.ScopedProxyUtils.isScopedTarget(Ljava/lang/String;)Z
	at org.springframework.context.event.EventListenerMethodProcessor.afterSingletonsInstantiated(EventListenerMethodProcessor.java:86)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:777)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:144)
	at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:85)
	at com.lanou3g.controller.Test.main(Test.java:10)

七:经过不断查找发现原来是spring-aop-4.0.0.RELEASE.jar的版本过低

打开上面写的网站,重新下载高版本的jar包,这次下载5.1.0版本的jar包,解压后导入项目,并build path

Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第7张图片
Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第8张图片
Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第9张图片

八:再次运行

运行结果显示成功,时代不断进步,jar包新版本也不断推出,新旧版本jar包之间的配合使用容易出问题。

Spring使用注解配置时异常信息报错之spring-aop-4.0.0.RELEASE.jar包下载方式_第10张图片

你可能感兴趣的:(乐在其中)