【发布时间】: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。这似乎是一个矛盾的问题,我正在解决它。