春天-TX:无法找到春天NamespaceHandler XML模式命名空间[http://www.springframework.org/schema/tx]

为什么我仍然得到呢?春天-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必须被包括在内,但它的存在。 这个命名空间有什么问题?我想停止拉我的头发,所以请告诉我这个命名空间无法找到的原因。

回答:

的问题可能是由您的使用汇编插件,它不明白春天处理机制,并覆盖在spring.handlers文件处理程序定义造成的。行为在这个线程中讨论:Idea to avoid that spring.handlers/spring.schemas get overwritten when merging multiple spring dependencies in a single jar

为了避免这个问题,一个选项是使用阴影插件为您的目的,如建议here。

以上是 春天-TX:无法找到春天NamespaceHandler XML模式命名空间[http://www.springframework.org/schema/tx] 的全部内容, 来源链接: utcz.com/qa/260016.html

回到顶部