【问题标题】:Unable to locate NamespaceHandler for namespace (http://www.springframework.org/schema/context)无法找到命名空间的 NamespaceHandler (http://www.springframework.org/schema/context)
【发布时间】:2014-02-04 22:08:05
【问题描述】:

我在 Spring 项目中遇到以下异常。即使我尝试了 stackoverflow 中建议的几种解决方案,我也无法解决。你能帮帮我吗?

java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 配置问题:无法定位命名空间的 NamespaceHandler [http://www.springframework.org/schema/context] 违规资源:类路径资源[springDAO.xml]

SpringDao.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:amq="http://activemq.org/config/1.0"    
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0-SNAPSHOT.xsd"
default-autowire="autodetect">

<!-- Database -->
<bean id="ds" class="org.springframework.jndi.JndiObjectFactoryBean" autowire="no">
    <property name="jndiName" value="java:comp/env/jdbc/datasource" />
</bean>   

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="ds" />
    <property name="persistenceUnitName" value="NewstrackPU"/>
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>
    <property name="jpaVendorAdapter">
        <bean
            class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">                
        </bean>
    </property>        
    <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
    </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- tx:annotation-driven configure transactions on any beans with @Transactional, and just after the JPA transaction manager is setup. -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:component-scan base-package ="com.abc.newstrack.dao"/>
<context:component-scan base-package ="com.abc.newstrack.service"/>

Spring 依赖项

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.5.6.SEC03</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>2.5.6.SEC03</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>2.5.6.SEC03</version>
    </dependency>

【问题讨论】:

  • 你的类路径中有 spring 和 spring-context。不要,要么使用 spring(它包含几乎所有东西)或使用单独的模块(spring-context 等)。还要确保你的类路径中没有冲突的 spring 版本(检查mvcn depenency:tree)。
  • 感谢 Deinum。这似乎是一个矛盾的问题,我正在解决它。

标签: java spring maven


【解决方案1】:

我下载了activemq-core-5.0-SNAPSHOT pom.xml。它使用 Spring 2.0.6 作为依赖项。我看到你有 Spring 2.5.6 SEC02 作为你的 spring 依赖项。

基于 activeMQ pom 文件,我相信您必须使用 spring 2.0.6 作为依赖项而不是 2.5.6?

至于您的命名空间没有得到解决的实际问题,通常是类路径中不存在依赖项的问题。在这种情况下,由于活动 mq 使用 Spring 2.0.6,它不在类路径中。

【讨论】:

    猜你喜欢
    • 2013-06-10
    • 1970-01-01
    • 2013-10-04
    • 2015-02-25
    • 2017-10-05
    • 2019-01-27
    • 1970-01-01
    • 2019-05-07
    • 2011-01-10
    相关资源
    最近更新 更多