【问题标题】:Error: Cannot locate BeanDefinitionParser for element [component-scan] after upgrading to Spring 3.2.3.RELEASE错误:升级到 Spring 3.2.3.RELEASE 后无法找到元素 [component-scan] 的 BeanDefinitionParser
【发布时间】:2013-08-11 20:37:53
【问题描述】:

将 spring 升级到 3.2.3.RELEASE 后,在 Eclipse 中启动 Tomcat 时出现以下错误:

ug 12, 2013 1:59:14 AM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalArgumentException: Cannot locate BeanDefinitionParser for element [component-scan].
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.findParserForElement(NamespaceHandlerSupport.java:63)
    at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseCustomElement(DefaultXmlBeanDefinitionParser.java:399)
    at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:358)
    at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions

这是我的 applicationContext.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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">

    <context:component-scan base-package="merchant" />    
     <context:component-scan
        base-package="merchant.domain" />
    <context:component-scan
        base-package="merchant.controller" />
    <context:component-scan
        base-package="merchant.repo" />
    <context:component-scan
        base-package="merchant.service" />

    <!-- Load Hibernate related configuration -->
    <import resource="hibernate-context.xml" />

    <tx:annotation-driven/>
    <mvc:annotation-driven/>

</beans>

我在网上搜索了很多解决方案,但找不到任何相关的解决方案。 请帮忙! 提前致谢!

【问题讨论】:

    标签: java rest spring-mvc xsd spring-ws


    【解决方案1】:

    这个错误很可能是因为升级后在类路径中找不到spring-context-3.2.3.RELEASE.jar。请检查您的依赖项并确保此 jar 在依赖项列表中。

    【讨论】:

    • 感谢您的回复。我已经检查过了。 jar 在类路径中正确找到。由于 Spring 的旧版本,我遇到了另一个问题,并且得到了解决。因此,它必须工作。但我仍然收到上述错误。
    • 奇怪..想不出别的,有没有办法检测到其他一些spring-context jar?另外,看看你能不能找到这个类型,org.springframework.context.config.ContextNamespaceHandler,这是处理context命名空间的类。
    • 我包含了spring-2.5.6.jar,它包含了上面的类。还是一样的错误。
    • 和我在xsi:schemaLocation里面的applicationContext.xml中提到的spring版本有什么关系吗?
    • spring-2.5.6 是旧版本。任何将 spring-context-3.2.3 与 spring-2.5.6 混合的理由,我都会继续删除旧版本。这应该可以解决问题。
    猜你喜欢
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 2021-06-10
    • 2013-08-28
    • 2023-03-16
    相关资源
    最近更新 更多