【发布时间】:2018-05-16 22:15:15
【问题描述】:
为什么我还是会收到这个?
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,但它就在那里。 这个命名空间有什么问题?我想停止拔头发,所以请告诉我找不到这个命名空间的原因。
【问题讨论】:
-
你确认 spring-tx 库确实放在你的war文件中了吗?
-
另外,您的
spring/config/beanLocations.xml中有什么内容?某种嵌套定义? -
不是,但是 maven-assembly-plugin 应该把它放在那里。 (这是一个 jar 文件。)我在几秒钟内包含
beanLocations.xml。 -
好的。添加您的 maven-assembly-plugin 配置,它可能是相关的。到目前为止,您发布的 xml 配置没有任何问题,我怀疑您的构建过程存在问题,或者在 beanLocations.xml 中存在问题。
-
好吧,再过一秒。
标签: java xml spring maven spring-mvc