2017-12-03 154 views
0

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

+0

你证实春天-TX库实际上是放在你的war文件? – eis

+0

另外,你的'spring/config/beanLocations.xml'中有什么?某种嵌套定义? – eis

+0

不是,但maven-assembly-plugin应该放在那里。 (这是一个jar文件。)我在一秒钟内包含'beanLocations.xml'。 – ntj

回答

1

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

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

+0

我希望这个答案能解决我的问题,所以我假设你的解决方案可以被接受,谢谢。 – ntj

+1

[此](https://issues.apache.org/jira/browse/MASSEMBLY-360)为约组装插件行为错误条目:有趣的部分是,它是权利2010已固定的,测试用例好。看起来似乎并没有,因为人们似乎仍然遇到这个问题,所以示例项目证明问题并在那里发表评论可能会使它在汇编插件(修复程序所属的地方)中得到修复。他们已经有一个过滤器来处理这个问题,但我想这只是无法正常工作。 – eis

+1

它的工作原理,经过几个小时的苦难后,无法感谢你足够的这个链接。 – ntj

相关问题