`
liyixing1
  • 浏览: 939483 次
  • 性别: Icon_minigender_1
  • 来自: 江西上饶
社区版块
存档分类
最新评论

Unable to locate Spring NamespaceHandler for XML schema namespace

阅读更多
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Config
uration problem: Unable to locate Spring NamespaceHandler for XML schema namespa
ce [http://www.springframework.org/schema/tx]

原因是因为在使用没有把jar包引进来!(org.springframework.transaction-.jar)。

mvn install assembly:assembly  -X,需要显示引入jar。

<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-tx</artifactId>
			<version>4.0.0.RELEASE</version>
		</dependency>



还有就是头部的
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
	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-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

这里的xmlns和schemaLocation要按照jar文件中提供的路径和版本写。


还需注意的是spring对xml的schema的描述文件都是spring.handlers  spring.schemas  spring.tooling

所以引入了多个spring的依赖包,他们都有META-INF/,如果他们的META-INF下面有同名文件,打包插件只会处理第一个。

该BUG具体
https://issues.apache.org/jira/browse/MASSEMBLY-360


以一般推荐使用另外的一个插件来进行打包,插件名称为:maven-shade-plugin,shade插件打包时在对spring.schemas文件处理上,它能够将所有jar里的spring.schemas文件进行合并,在最终生成的单一jar包里,spring.schemas包含了所有出现过的版本的集合,要使用shade插件,必须在pom进行如下配置:

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-shade-plugin</artifactId>  
    <version>1.4</version>  
    <executions>  
        <execution>  
            <phase>package</phase>  
            <goals>  
                <goal>shade</goal>  
            </goals>  
            <configuration>  
                <transformers>  
                    <transformer  
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
                        <resource>META-INF/spring.handlers</resource>  
                    </transformer>  
                    <transformer  
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
                        <mainClass>com.chenzhou.examples.Main</mainClass>  
                    </transformer>  
                    <transformer  
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
                        <resource>META-INF/spring.schemas</resource>  
                    </transformer>  
                </transformers>  
            </configuration>  
        </execution>  
    </executions>  
</plugin>  


上面配置文件中有一段定义:

<transformer  
    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
    <resource>META-INF/spring.schemas</resource>  
</transformer>  


上面这段配置意思是把spring.handlers和spring.schemas文件以append方式加入到构建的jar包中,这样就不会存在出现xsd找不到的情况。


调用mvn clean install命令进行构建,构建成功后打开工程target目录,发现生成了2个jar

original开头的是不包含依赖包的
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics