Spring升級到5.2之後,項目在無網絡的情況下無法啓動項目。報xml的錯誤

項目在沒升級spring5.2之前是可以在沒有網絡的情況下編譯啓動運行的。升級之後就報錯了。

錯誤:

[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@290c266c{/siam,file:///D:/projectdata/newsiam/siam/siam-server/siam-server-webapp/src/main/webapp/,UNAVAILABLE}{file:///D:/projectdata/newsiam/siam/siam-server/siam-server-webapp/src/main/webapp/}
MultiException[org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 26 in XML document from ServletContext resource [/WEB-INF/spring-configuration/siam-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 26; columnNumber: 48; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'sec:http'., org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 26 in XML document from ServletContext resource [/WEB-INF/spring-configuration/siam-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 26; columnNumber: 48; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'sec:http'., org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 26 in XML document from ServletContext resource [/WEB-INF/spring-configuration/siam-security.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 26; columnNumber: 48; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'sec:http'., javax.servlet.ServletException: api@17a1a==org.springframework.web.servlet.DispatcherServlet,jsp=null,order=2,inst=false, javax.servlet.ServletException: console@38b6e557==org.springframework.web.servlet.DispatcherServlet,jsp=null,order=2,inst=false]
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:731)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:374)
	

我的security.xml配置

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:c="http://www.springframework.org/schema/c"
       xmlns:sec="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

主要原因就是這個security.xml的配置造成的。

首先,看到spring-security.xsd引用是沒有指定版本的。報錯的原因,就是沒有找到這個xsd,那麼spring肯定是本地找這個xsd沒有找到,然後聯網去找,網絡也是斷的,所以纔會造成報錯。

那麼爲什麼會找不到呢。就要看spring5.2的jar包了。

spring xsd獲取是通過spring.schemas配置鍵值對獲取的,如下是路徑:

打開spring.schemas,就會發現一個坑

因爲我沒指定版本,而沒指定版本的key的地址是https的,而我引用的是http的地址,所以這個schema中沒有與我不指定版本相匹配的key,當然在本地找不到了,就會到網絡上查找,也連不通,最後就報錯了。

把本地引用的xsd改成https就可以正常在無網絡環境使用了。

發佈了26 篇原創文章 · 獲贊 5 · 訪問量 9587
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章