爲什麼我仍然得到呢?春天-TX:無法找到春天NamespaceHandler XML模式命名空間[http://www.springframework.org/schema/tx]
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [../beans/Character.xml]
Offending resource: class path resource [spring/config/beanLocations.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
Offending resource: class path resource [spring/beans/Character.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:72)
我讀過許多文章中針對此問題,配置爲根據他們我的XML-S。
我的問題的XML看起來像這樣:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Character Data Access Object -->
<bean id="characterDao" class="com.got.common.dao.CharacterDao" >
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
春-TX包括在我的pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
beanLocations.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- Database Configuration -->
<import resource="../database/DataSource.xml"/>
<import resource="../database/hibernate.xml"/>
<!-- Beans Declaration -->
<import resource="../beans/Character.xml"/>
</beans>
組裝插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.got.common.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
我不知道該AOP必須被包括在內,但它的存在。 這個命名空間有什麼問題?我想停止拉我的頭髮,所以請告訴我這個命名空間無法找到的原因。
你證實春天-TX庫實際上是放在你的war文件? – eis
另外,你的'spring/config/beanLocations.xml'中有什麼?某種嵌套定義? – eis
不是,但maven-assembly-plugin應該放在那裏。 (這是一個jar文件。)我在一秒鐘內包含'beanLocations.xml'。 – ntj