2017-12-03 155 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

相關問題