spring.handlers、spring.schemas、spring.tooling被覆盖的三种解决方式

    在用到spring时,本地IDE里面跑的很正常,但是打jar包后在集群上运行时报错。

    查找资料后确定了问题的根源,由于在依赖中调用了spring的许多包,每个包都有自己的spring.schemas文件,会存在文件覆盖的情况。

报错信息为:

Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace

解决方法:

方法一:

    修改maven的settings.xml文件,在镜像中添加

<mirror>
  <id>repo2</id>
  <mirrorOf>central</mirrorOf>
  <name>Human Readable Name for this Mirror.</name>    
  <url>http://repo2.maven.org/maven2/</url>
</mirror>

    添加到<mirrors>与</mirrors>之间,注意原先是被注释掉的,要在<mirrors>后面粘贴上

方法二:

    使用maven的打包插件maven-shade-plugin,把spring.handlers、spring.schemas、spring.tooling三个文件设置成增量保存模式,即Appending

    在maven的pom.xml中,在<project>和</project>之间加上下面的代码

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-shade-plugin</artifactId>  
    <version> 1.7.1</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.AppendingTransformer">  
                        <resource>META-INF/spring.schemas</resource>  
                    </transformer>  
                    <transformer  
                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
                        <mainClass>com.chenzhou.test.Main</mainClass>  
                    </transformer>  
                </transformers>  
            </configuration>  
        </execution>  
    </executions>  
</plugin>

    然后在maven窗口的plugin中即可找到package,就是这个打包工具

方法三:

    这种方法比较小白,操作简单,无论怎么打包,用什么工具,只要找到spring.handlers、spring.schemas、spring.tooling这三个文件,用我提供的这三个完整的文件覆盖即可

    一般来说,打完包之后,这三个文件都在jar包下面的META-INF路径下,直接复制完整文件到这个目录下覆盖即可

    下载链接为http://files.cnblogs.com/files/starwater/spring.zip  包含了spring.handlers、spring.schemas、spring.tooling这三个完整的文件

原文地址:https://www.cnblogs.com/starwater/p/6946332.html