Java 加载SpringXML引发SAXParseException

Java 加载SpringXML引发SAXParseException,java,spring,Java,Spring,我在eclipse中编写了一个使用spring和hibernate的应用程序。应用程序在eclipse中运行时工作正常。我使用maven将该项目打包成一个可执行的jar文件,并且在运行jar时遇到一个SAXParseException 这是个例外 org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 69; schema_reference.4: Failed to read schema document 'http:

我在eclipse中编写了一个使用spring和hibernate的应用程序。应用程序在eclipse中运行时工作正常。我使用maven将该项目打包成一个可执行的jar文件,并且在运行jar时遇到一个SAXParseException

这是个例外

org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 69; schema_reference.4:     Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-2.5.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the doc
t <xsd:schema>.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaWarning(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument1(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:76)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadDocument(XmlBeanDefinitionReader.java:428)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:540)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:454)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.lilly.moveit.awetosdd.AweToSddMover.main(Test.java:49)
项目结构看起来像

Project
-----------src/main/java
-----------src/main/resources
-----------pom.xml
文件spring.xml位于src/main.resources中

我的pom.xml看起来像

<project xmlns="http://maven.apache.org/POM/4.0.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.lilly.moveit.awetosdd</groupId>
  <artifactId>testmove</artifactId>
  <packaging>jar</packaging>
  <version>1.0</version>
  <name>testmove</name>
  <url>http://maven.apache.org</url>

<properties>
    <spring.version>4.0.3.RELEASE</spring.version>  
    <jdk.version>1.7</jdk.version>
    <hibernate.version>4.2.0.Final</hibernate.version>
</properties>

<dependencies>

    <dependency>
        <groupId>com.abc.def</groupId>
        <artifactId>customjar</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>       

    <dependency>  
        <groupId>org.springframework</groupId>  
        <artifactId>spring-webmvc</artifactId>  
        <version>${spring.version}</version>  
    </dependency>

     <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-remoting</artifactId>
        <version>2.0.8</version>
    </dependency>

    <dependency>  
        <groupId>org.springframework</groupId>  
        <artifactId>spring-web</artifactId>  
        <version>${spring.version}</version>  
    </dependency> 

    <dependency>
        <groupId>xalan</groupId>
        <artifactId>xalan</artifactId>
        <version>2.7.1</version>
    </dependency>

    <dependency>
        <groupId>commons-httpclient</groupId>
        <artifactId>commons-httpclient</artifactId>
        <version>3.1</version>
    </dependency>

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.9</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <archive>
                <manifest>
                          <mainClass>com.abc.test.Test</mainClass>
                </manifest>
                </archive>
            </configuration>
        </plugin>


        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

4.0.0
com.lilly.moveit.awetosdd
测试移动
罐子
1
测试移动
http://maven.apache.org
4.0.3.1发布
1.7
4.2.0.4最终版本
com.abc.def
海关总署
1
朱尼特
朱尼特
3.8.1
测试
org.springframework
SpringWebMVC
${spring.version}
org.springframework
春季远程处理
2.0.8
org.springframework
弹簧网
${spring.version}
沙兰
沙兰
2.7.1
commons httpclient
commons httpclient
3.1
通用编解码器
通用编解码器
1.9
org.apache.maven.plugins
maven javadoc插件
2.9.1
org.apache.maven.plugins
maven编译器插件
2.0.2
${jdk.version}
${jdk.version}
org.apache.maven.plugins
maven jar插件
2.4
com.abc.test.test
org.apache.maven.plugins
maven阴影插件
2.3
包裹
阴凉处

问题似乎出在shade插件中。在不同spring JAR中定义的命名空间处理程序和模式正在被覆盖。将以下内容添加到shade插件配置的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>

META-INF/spring.handlers
META-INF/spring.schemas

也可以考虑使用无版本的模式定义,使您对版本号更改不可知。所有XSD文件首先在类路径内进行验证,并且只有在未找到的情况下才能进入网络。

< p>问题似乎在阴影插件中。在不同spring JAR中定义的命名空间处理程序和模式正在被覆盖。将以下内容添加到shade插件配置的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>
<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-webmvc</artifactId>  
    <version>${spring.version}</version>  
</dependency>

 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-remoting</artifactId>
    <version>2.0.8</version>
</dependency>

<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-web</artifactId>  
    <version>${spring.version}</version>  
</dependency> 

META-INF/spring.handlers
META-INF/spring.schemas

也可以考虑使用无版本的模式定义,使您对版本号更改不可知。所有XSD文件首先在类路径内进行验证,并且只有在未找到的情况下才能进入网络。

< p>问题似乎在阴影插件中。在不同spring JAR中定义的命名空间处理程序和模式正在被覆盖。将以下内容添加到shade插件配置的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>
<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-webmvc</artifactId>  
    <version>${spring.version}</version>  
</dependency>

 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-remoting</artifactId>
    <version>2.0.8</version>
</dependency>

<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-web</artifactId>  
    <version>${spring.version}</version>  
</dependency> 

META-INF/spring.handlers
META-INF/spring.schemas

也可以考虑使用无版本的模式定义,使您对版本号更改不可知。所有XSD文件首先在类路径内进行验证,并且只有在未找到的情况下才能进入网络。

< p>问题似乎在阴影插件中。在不同spring JAR中定义的命名空间处理程序和模式正在被覆盖。将以下内容添加到shade插件配置的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>
<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-webmvc</artifactId>  
    <version>${spring.version}</version>  
</dependency>

 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-remoting</artifactId>
    <version>2.0.8</version>
</dependency>

<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-web</artifactId>  
    <version>${spring.version}</version>  
</dependency> 

META-INF/spring.handlers
META-INF/spring.schemas

也可以考虑使用无版本的模式定义,使您对版本号更改不可知。所有XSD文件首先在类路径内进行验证,并且只有在未找到的情况下才能进入网络。

<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-webmvc</artifactId>  
    <version>${spring.version}</version>  
</dependency>

 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-remoting</artifactId>
    <version>2.0.8</version>
</dependency>

<dependency>  
    <groupId>org.springframework</groupId>  
    <artifactId>spring-web</artifactId>  
    <version>${spring.version}</version>  
</dependency> 
另一个注意事项建议在配置xml时使用无版本的xsd文件,这将确保您始终拥有属于您的spring版本的最新版本

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/jee
      http://www.springframework.org/schema/jee/spring-jee.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd">
另请参见和maven shade插件

另一个注意事项建议在配置xml时使用无版本的xsd文件,这将确保您始终拥有属于您的spring版本的最新版本

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/jee
      http://www.springframework.org/schema/jee/spring-jee.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd">
另请参见和maven shade插件

另一个注意事项建议在配置xml时使用无版本的xsd文件,这将确保您始终拥有属于您的spring版本的最新版本

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/jee
      http://www.springframework.org/schema/jee/spring-jee.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd">
另请参见和maven shade插件

另一个注意事项建议在配置xml时使用无版本的xsd文件,这将确保您始终拥有属于您的spring版本的最新版本

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:jee="http://www.springframework.org/schema/jee"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/aop
      http://www.springframework.org/schema/aop/spring-aop.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/jee
      http://www.springframework.org/schema/jee/spring-jee.xsd
      http://www.springframework.org/schema/tx
      http://www.springframework.org/schema/tx/spring-tx.xsd">

参见Maven HuffelPuxu/P>认真考虑将命名空间模式位置更新到它们的新版本。http://www.springframework.org/schema/beans/spring-beans-2.5.xsd“”没有意义?从这里可以阅读,但您可能有本地网络问题。@SotiriosDelimanolis Ii确实将SpringBeans更改为最新版本,但我仍然得到相同的版本issue@JimGarrison这似乎是一个网络问题,但我可以访问互联网。我是否需要对spring的设置进行任何更改。我不确定如何检测它是否真的是一个网络问题。因为它在eclipse中工作得很好。只有当我运行JAR命令并在浏览器中输入URL并查看发生了什么时,才会发生这种情况。您应该看到XSD文件。认真考虑将命名空间模式位置更新到它们的新版本。http://www.springframework.o