2017-12-03 7 views
0

は、なぜ私はまだこれを取得していますか?春-TX:XMLスキーマの名前空間の春NamespaceHandlerを見つけることができません[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

spring-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

問題を回避するには、1つのオプションは、hereのような目的にシェードプラグインを使用することです。

+0

この回答が私の問題を解決することを願っていますので、あなたの解決策が受け入れられると思います。ありがとうございます。 – ntj

+1

[this](https://issues.apache.org/jira/browse/MASSEMBLY-360)は、アセンブリプラグインの動作に関するバグエントリです。興味深い点は、2010年に既に修正されていると主張されています。よく人々がまだこの問題にぶつかっているように思われないので、問題を証明してそこにコメントするサンプルプロジェクトは、アセンブリのプラグイン(修正が所属する場所)で修正される可能性があります。彼らはすでにこれを処理するためのフィルタを持っていますが、私はそれがちょうど正しく動作しないと思います。 – eis

+1

これは数時間の苦しみの後、このリンクのために十分にあなたに感謝することはできません。 – ntj

関連する問題