下午在搭建一個基於dubbo和spring的服務端項目。結果打包成jar後各類報錯。java
起初是由於idea的機制,致使META-INF下本身的Mainfest.mf老是莫名被覆蓋,因而報找不到主函數。後來利用artfacts-》jar-》empty方式配置jar包,並把META-INF文件夾和mainfest.mf文件放在rescorces文件夾下解決了。spring
後來是dubbo已經中止維護,因此xds文件經過url已經拿不到了,查資料發現dubbo.jar裏是帶有xds文件的,spring怎麼讀不到呢? 原來又是idea的打包功能的坑,jar包下的META-INF目錄下,有兩個跟spring相關的文件:spring.handlers、spring.schemas,裏面都只包含了一條配置,其餘的xds配置都不見了!!apache
無奈,仍是用maven吧,因而用 maven的shade打包插件來搞定app
在stackoverflow上找到了答案:http://stackoverflow.com/questions/1937767/spring-3-0-unable-to-locate-spring-namespacehandler-for-xml-schema-namespacemaven
下面的是pom.xml中關於打包部分的配置,能夠看見配置了spring.handlers和srping.schemas而且直接指定main入口。ide
另外須要注意的是dubbo只能認META-INF/srping目錄下的xml文件爲spring配置文件。因此要本身創建一個META-INF/spring目錄結構,把spring配置文件放進去,而後把這個目錄結構再給扔到idea標記爲resources的文件夾下,一般就是src/main/resources/META-INF/srping/applicationContent.xml 啦,這樣一打包spring配置文件才能恰好知足dubbo的奇葩要求。函數
<build>ui
<finalName>org.yueue.vita</finalName> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version> 1.7.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <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> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.alibaba.dubbo.container.Main</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins></build>