打可執行jar包執行時依賴spring包異常

Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]html

原本比較習慣直接用eclipse裏面的export成可運行jar包,開始選擇的library handling 是第一個選項,結果運行後一直報下面的錯誤;java

 

java -jar testmq.jar
六月 18, 2018 7:11:16 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@17a7cec2: startup date [Mon Jun 18 19:11:16 CST 2018]; root of context hierarchy
六月 18, 2018 7:11:16 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [Producer.xml]
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [Producer.xml]spring

        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
        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:301)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1408)
        at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1401)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:172)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:142)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:94)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:508)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:392)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:336)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
        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:613)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:514)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at com.autohome.mq.testmq.ProducerMain.main(ProducerMain.java:16)spring-mvc

 

查詢了好多一樣的問題,覺得是直接export不太對,須要用maven打包,好比看到了下面這個連接https://www.cnblogs.com/icewee/articles/3703491.html,是由於缺什麼包致使;mvc

而後換成了mavn打包,結果仍是不太對,和我用export導出來的效果同樣,查了好久都沒有查到緣由;eclipse

剛開始,用mvn打包,直接都是打成文件的 maven

https://www.cnblogs.com/dzblog/p/6913809.htmlspa

按這個方式去打包,結果都生成了別的lib包,沒有直接打進jar包;因此只能在當前目錄下運行;.net

而後看到了這篇文章  https://blog.csdn.net/birdben/article/details/51951651插件

明白了緣由,是由於由於的plugin不對;

主要使用了maven-jar-plugin和maven-dependency-plugin這兩個Maven的插件,maven-jar-plugin負責構建jar包,maven-dependency-plugin負責導出全部依賴的jar包,這裏咱們使用了maven-assembly-plugin插件,這個插件能夠將全部當前jar依賴的全部jar包打包到當前jar裏面,這樣就不須要導出全部依賴的jar包了,直接運行jar就能夠了,實在太方便了 ^_^

 

可是這樣仍是不行,感受和export的效果實際上是一致的;因而又找了一些文章

https://blog.csdn.net/qing0706/article/details/51612040

,總算找到了緣由;結果也是確實是由於

spring.handlers、spring.schemas,打開這兩個文件一看,裏面都只包含了spring-mvc的配置

須要在pom的打包後面添加別的插件,

再一想,我用maven和eclipse打包效果同樣,是否是eclipse自己就有這樣的方法了,

因而,嘗試了一下,過然如此;

 

 

來源於  https://www.cnblogs.com/jiangwangxiang/p/8596785.html  中間部分

相關文章
相關標籤/搜索