maven打包後啓動程序遇到遇到解析spring的applicationContext.xml文件報錯,錯誤如下:
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-2.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 <xs |
這是因爲maven打包時,並沒有將程序中spring jar包中的META-INF目錄下的spring.schemas文件中的內容採用追加模式,而是採用覆蓋策略。
可能你的maven pom.xml打包配置如下:
<plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass></mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> |
這是因爲這樣的配置採用的模式是文件覆蓋,打包後spring-schema的內容丟失。
網上的許多帖子上給出的解決方案,但是並解決(有可能是自己mvn包的原因,shade的jar包下載下來的),程序無法識別:org.apache.maven.plugins.shade.resource.AppendingTransformer類。
maven-shade-plugin插件配置如下: <plugin>
|
最後,本人把<transformer>配置去掉,結果spring. schemas的內容採用了追加方式。
但是本人的項目依然沒有運行成功,最後自己採用無依賴的jar,手動將依賴jar包複製到項目中,才解決了問題。