今天在把自己的項目轉為maven架構的時候,居然碰到了一個很奇葩的問題具體如下:
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 23 in XML document from class path resource [spring-mvc.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cos-all-limited.1.2: An ''all'' model group must appear in a particle with '{'min occurs'}'='{'max occurs'}'=1, and that particle must be part of a pair which constitutes the '{'content type'}' of a complex type definition.
Caused by: org.xml.sax.SAXParseException: cos-all-limited.1.2: An ''all'' model group must appear in a particle with '{'min occurs'}'='{'max occurs'}'=1, and that particle must be part of a pair which constitutes the '{'content type'}' of a complex type definition.
因為之前的applicationContext.xml編碼問題,然后就以為是這個文檔也是編碼的問題。百度了很久,最后就差把這個xml文件手打了,依然報的這個錯誤,真真被弄得是焦頭爛額了,編碼問題,不太懂啊。
然后,覺得是不是jar包導入的有問題(方向對了,但是我犯了個致命的錯誤),於是,把原來項目里的jar包重新導入到maven生成的war包中,再啟動,依然是這個錯誤,要抓狂了都。
其實,正確的方法應該是先把該項目總的jar包刪除后,再從原項目導入jar包,這個是肯定不會出問題的。因為是用maven控制的包的導入,只能是在導入的時候出現了包沖突的問題,造成了解析錯誤,重新查看jar包引入的過程,在 這篇博文中發現,原來是在導入dbcp的jar包時,又引入了一個xml文檔解析的jar包,造成了沖突。
正確的引入dbcp依賴的方法是:
排除依賴包
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.1</version>
<exclusions>
<exclusion>
<artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId>
</exclusion>
</exclusions>
</dependency>
大家共勉啊!!!