Spring MAVEN projects packaged as executable jar packages

Source: Internet
Author: User

Packing with assembly always error:

Shangyanshuodemacbook-pro:target shangyanshuo$ Java-jar jobscrawler-1.0-snapshot-jar-with-Dependencies.jar17-04-30 15:52:43,337 INFO Org.springframework.context.support.ClassPathXmlApplicationContext ( abstractapplicationcontext.java:495) # # refreshing org[email protected]22927a81:startup date [Sun Apr 15:52:43 CST 201 7]; Root of context Hierarchy17-04-30 15:52:43,489 INFO Org.springframework.beans.factory.xml.XmlBeanDefinitionReader ( xmlbeandefinitionreader.java:315) # # Loading XML Bean Definitions fromclassPath Resource [spring/applicationcontext-Mybatis.xml]17-04-30 15:52:47,269 INFO Org.springframework.beans.factory.xml.XmlBeanDefinitionReader ( xmlbeandefinitionreader.java:315) # # Loading XML Bean Definitions fromclassPath Resource [spring/Applicationcontext.xml] Exception in Thread"Main" Org.springframework.beans.factory.parsing.BeanDefinitionParsingException:Configuration problem:unable to Locate Spring Namespacehandler forXML schema namespace [http://Www.springframework.org/schema/context]Offending resource:classPath Resource [spring/Applicationcontext.xml] at Org.springframework.beans.factory.parsing.FailFastProblemReporter.error ( Failfastproblemreporter.java:68) at Org.springframework.beans.factory.parsing.ReaderContext.error (Readercontext.java:85) at Org.springframework.beans.factory.parsing.ReaderContext.error (Readercontext.java:80) at Org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error ( Beandefinitionparserdelegate.java:316) at Org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement ( Beandefinitionparserdelegate.java:1416) at Org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement ( Beandefinitionparserdelegate.java:1409) at Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions ( Defaultbeandefinitiondocumentreader.java:184) at Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions ( Defaultbeandefinitiondocumentreader.java:140) at Org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions ( Defaultbeandefinitiondocumentreader.java:111) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions ( Xmlbeandefinitionreader.java:493) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions ( Xmlbeandefinitionreader.java:390) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( Xmlbeandefinitionreader.java:334) at Org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions ( Xmlbeandefinitionreader.java:60W) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( Abstractbeandefinitionreader.java:174) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( Abstractbeandefinitionreader.java:209) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( Abstractbeandefinitionreader.java:180) at Org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions ( Abstractbeandefinitionreader.java:243) 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:131) at Org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory ( Abstractapplicationcontext.java:522) at Org.springframework.context.support.AbstractApplicationContext.refresh (Abstractapplicationcontext.java: 436) at Org.springframework.context.support.ClassPathXmlApplicationContext.<init> (classpathxmlapplicationcontext.java:139) at Org.springframework.context.support.ClassPathXmlApplicationContext.<init> (classpathxmlapplicationcontext.java:83) at Com.jobscrawler.crawlers.ShhCrawler.main (Shhcrawler.java:48)

Read an article on the Internet that this is a bug in the assembly package spring project. See also (http://www.cnblogs.com/liqiu/p/4508848.html)

It is said that the reason is that more than one jar package in spring contains Spring.handlers and Spring.schemas files, and assembly only the first encountered files into the jar package, the later encountered will skip.

The solution is to abandon assembly and use shade Plug-in to package. The Spring.handlers and Spring.schemas files are included in the shade packaging configuration to ensure that the information of the two files in other spring jars is not omitted.

Here is a very simple example of a MAVEN project with only four files, in the code re-attachment:

Spring MAVEN projects packaged as executable jar packages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.