Spring application not taking spring.schemas into account


I have a Spring batch that uses spring-boot 0.5.0M2. I use the assembly jar-with-dependencies to generate an executable JAR file. I have checked that the JAR is generated with the proper dependencies, i.e. that all required Sprinf xsds are located where they should be, and that the spring-boot plugin has generated a proper META-INF/spring.schemas.

I run my app from a Cygwin terminal, but due to the NTLM authentication my proxy requires, I have no network access from the Cygwin shell.

If I run my app with mvn spring-boot:run it works. However in production the batch will be ran with java -jar myExecutableJar.jar and I am pretty certain that the server will not have access to Internet.

In this case I get the following error:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 :: Spring Boot ::

2013-12-12 17:15:42,197 INFO [fr.foo.my.app.MyBatch] - <Starting MyBatch on UC401711VW7JAV1 with PID 6848 (C:\nicolas\git\foobatch\target\indexer-batch-0.2.0-jar-with-dependencies.jar started by S818203)>
2013-12-12 17:16:03,481 WARN [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Ignored XML validation warning>
org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 12; schema_reference.4 : Echec de la lecture du document de sch▒ma 'http://www.springframework.org/schema/beans/spring-beans-3.2.xsd' pour les raisons suivantes : 1) Le document est introuvable ; 2) Le document n'a pas pu ▒tre lu ; 3) L'▒l▒ment racine du document n'est pas <xsd:schema>.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out: connect
        at java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
        at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.net.PlainSocketImpl.connect(Unknown Source)
        at java.net.SocksSocketImpl.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at java.net.Socket.connect(Unknown Source)
        at sun.net.NetworkClient.doConnect(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.openServer(Unknown Source)
        at sun.net.www.http.HttpClient.<init>(Unknown Source)
        at sun.net.www.http.HttpClient.New(Unknown Source)
        at sun.net.www.http.HttpClient.New(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
        at [...]

So I interpret this as the app trying to download spring-beans-3.2 XSD instead of taking into account spring.schemas and use the classpath resource that is present in the JAR.

Is there a way to force the Spring context to do this?

Thanks for helping!

By : Nikojiro


The most common cause of this error is using explicit versioned schema URLs in XML, and then accidentally inclusding an older version of the relevant JAR in your classpath. E.g. if you refer to spring-beans-4.0.xsd in an XML header but include spring-context:3.2.* in your transitive dependencies.

By : Dave Syer

This video can help you solving your question :)
By: admin