gpt4 book ai didi

java - spring-tx : Unable to locate Spring NamespaceHandler for XML schema namespace [http://www. springframework.org/schema/tx]

转载 作者:行者123 更新时间:2023-12-02 11:55:42 31 4
gpt4 key购买 nike

为什么我仍然收到此消息?

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>

Spring-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 是否也必须包含在内,但它就在那里。这个命名空间有什么问题吗?我不想再费劲了,所以请告诉我找不到这个命名空间的原因。

最佳答案

该问题可能是由于您使用的 assembly-plugin 引起的,它不理解 spring 处理程序机制并覆盖了 spring.handlers 文件中的处理程序定义。此线程中讨论了行为:Idea to avoid that spring.handlers/spring.schemas get overwritten when merging multiple spring dependencies in a single jar

为了避免这个问题,一种选择是使用阴影插件来达到您的目的,如建议的here .

关于java - spring-tx : Unable to locate Spring NamespaceHandler for XML schema namespace [http://www. springframework.org/schema/tx],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47616570/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com