Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
88 views
in Technique[技术] by (71.8m points)

java - How to stop spring resolving schemaLocation from internet

My application used to work fine during the development. But when it is being deployed environment without internet it started to complain because of spring-security-oauth2 schema location. My complete schema declaration was below.

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oauth="http://www.springframework.org/schema/security/oauth2" 
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.2.xsd
http://www.springframework.org/schema/security/oauth2 
http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-4.3.xsd">

It worked fine when the internet is available. But without internet, it could not resolve schemalLocation. The error is:

2021-01-20 10:25:31,784 ERROR [org.springframework.web.context.ContextLoader] - <Context initialization failed>
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 124 in XML document from class path resource [-----.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: ---; columnNumber: --; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'oauth:resource-server'.

The reason is, if you check "spring.schema" of spring-security-oauth2, it is referring only "https" URLs. While most of the other spring project's spring.schema is referring to "HTTP" URLs. (It is a separate question why it is so!) Replacing HTTP URL with HTTPS fixes my issue.

Several other people also faced issue because of spring resolving schemaLocaion from the internet for example: Spring schemaLocation fails when there is no internet connection

Question: Is there a way to restrict spring from resolving schemaLocation from the internet and get an error if it is not resolved by jars in classpath? Because that causes the issue could not be identified during development but comes later on production.

question from:https://stackoverflow.com/questions/65893685/how-to-stop-spring-resolving-schemalocation-from-internet

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...