org.springframework.beans.factory.BeanDefinitionStoreException,解析XML文档的意外异常

时间:2015-09-09 16:04:58

标签: spring

执行spring程序时,抛出以下异常:

Sep 09, 2015 9:16:00 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1099f62: startup date [Wed Sep 09 21:16:00 IST 2015]; root of context hierarchy
Sep 09, 2015 9:16:00 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:414)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
    at
.... 


org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
            at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
                at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
                at Application.main(Application.java:11)
            Caused by: java.lang.NoClassDefFoundError: org/springframework/aop/TargetSource
                at org.springframework.context.annotation.AnnotationConfigUtils.registerAnnotationConfigProcessors(AnnotationConfigUtils.java:140)
                at org.springframework.context.annotation.AnnotationConfigBeanDefinitionParser.parse(AnnotationConfigBeanDefinitionParser.java:47)
            at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:174)
            ... 14 more
        Caused by: java.lang.ClassNotFoundException: 
org.springframework.aop.TargetSource
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        ... 24 more

弹簧配置如下:

<?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"
 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-3.2.xsd">

    <context:annotation-config/>
    <context:component-scan base-package="com.test"/>
</beans>

我无法知道如何解决此问题。请让我知道需要添加任何jar来解决此问题。

3 个答案:

答案 0 :(得分:1)

Install

你不能看到这条错误信息吗?

你需要org.springframework.aop包

添加spring-aop-x.x.x.jar来解决问题。

答案 1 :(得分:0)

@Horizo​​n_Net,我也可以通过将spring-aop-4.3.3.jar添加到我的spring库文件夹来解决此问题。谢谢@ keshav-pradeep-ramanath!

答案 2 :(得分:0)

我正在为我的自包含的jar着色以节省空间,并且在从3.2.6升级到spring-context 4.3.4(spring-context依赖于spring-aop)后,我开始遇到这个问题。所以我要做的是将它作为包含过滤器配置添加到我的maven-shade-plugin中。