简体   繁体   中英

How can I run my Spring apps offline?

I have a Spring application (not a web app) that should be possible to run offline. However, when I try to do that, it crashes with this error message:

- Loading XML bean definitions from class path resource [applicationContext.xml]
21220 [main] WARN  org.springframework.beans.factory.xml.XmlBeanDefinitionReader 
 - Ignored XML validation warning
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tool/spring-tool-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <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)
...

This is caused by Spring not being able to find the schemas, as they are online and Spring is offline. How can I run my Spring apps offline?

Spring jars contain META-INF/spring.handlers and META-INF/spring.schemas files. To avoid overwriting the files when aggregating dependencies to one jar you can use the Maven Shade plugin .

Here what I did. I manually edited the jar file. First extracted META-INF/spring.schemas file. Added there schemes which spring tries to download from internet. In my case it was spring-beans.xsd and spring-tool.xsd. Like this:

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans.xsd

And another spring-tool.xsd schema I've downloaded and added to the root of project. Then also added this line to spring.schemas, like this:

http://www.springframework.org/schema/tool/spring-tool.xsd=spring-tool.xsd One minus is every time when you rebuild your project you have to edit the jar file.

In the internet people say you have to add corresponding dependencies to project. For example spring-beans. But it didn't help me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM