민서네집

인터넷에 연결 안되면 Spring Framework 에러 발생. 본문

Spring

인터넷에 연결 안되면 Spring Framework 에러 발생.

브라이언7 2014. 9. 4. 11:10

Tomcat v7.0 을 로컬에서 돌리고 있는데, 랜선을 뺀 상태로 구동시키니까 다음과 같은 에러가 나면서 Console에 Stack Trace가 길게 찍힌다.


Spring Framework의 버전: 3.1.2


org.xml.sax.SAXParseException; lineNumber: 95; columnNumber: 84; schema_reference.4: 스키마 문서 'http://www.springframework.org/schema/util/spring-util-3.2.xsd' 읽기를 실패했습니다. 원인: 1) 문서를 찾을 수 없습니다. 2) 문서를 읽을 수 없습니다. 3) 문서의 루트 요소가 <xsd:schema>가 아닙니다.


Caused by: java.net.UnknownHostException: www.springframework.org


2014-09-04 10:34:22,195 [localhost-startStop-1] ERROR [org.springframework.web.servlet.DispatcherServlet] Context initialization failed

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 95 in XML document from class path resource [spring/spring.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 95; columnNumber: 84; cvc-complex-type.2.4.c: 일치하는 와일드 카드 문자가 엄격하게 적용되지만 'util:properties' 요소에 대한 선언을 찾을 수 없습니다.


Caused by: org.xml.sax.SAXParseException; lineNumber: 95; columnNumber: 84; cvc-complex-type.2.4.c: 일치하는 와일드 카드 문자가 엄격하게 적용되지만 'util:properties' 요소에 대한 선언을 찾을 수 없습니다.


2014-09-04 10:34:22,396 [http-bio-8080-exec-1]  WARN [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] Ignored XML validation warning

org.xml.sax.SAXParseException; lineNumber: 95; columnNumber: 84; schema_reference.4: 스키마 문서 'http://www.springframework.org/schema/util/spring-util-3.2.xsd' 읽기를 실패했습니다. 원인: 1) 문서를 찾을 수 없습니다. 2) 문서를 읽을 수 없습니다. 3) 문서의 루트 요소가 <xsd:schema>가 아닙니다.


Caused by: java.net.UnknownHostException: www.springframework.org

Spring 설정 파일에서 95번째 줄에


<util:properties id="prop" location="classpath:spring/application.properties"/>


이렇게 있었는데, 이 줄을 읽지 못해서 에러가 난 것이다.


이 줄을 주석 처리하고, 소스 상에서


@Autowired

Properties prop;


prop.getProperty("aaa")


이렇게 properties 파일에서 가져오는 부분을 없애고, application.properties 파일에 있던 문자열로 치환 했더니 정상 작동했다.


이 에러가 나면 Tomcat이 서비스를 하지 못하고, 에러를 내지만, 이렇게 에러가 난 상태에서 인터넷을 연결하고, 웹브라우저에서 요청이 들어오면 Spring 프레임워크가 restart 하면서 정상적으로 서비스를 시작한다.


인터넷이 안되는 환경에서도 정상적으로 Spring Framework를 구동하기 위해서는 어떻게 해야할까?


참고로 Spring 설정 파일의 첫부분은 다음과 같이 되어 있다.


<?xml version="1.0" encoding="UTF-8"?>
<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:mvc="http://www.springframework.org/schema/mvc"
	xmlns:task="http://www.springframework.org/schema/task"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:util="http://www.springframework.org/schema/util"
	xmlns:oxm="http://www.springframework.org/schema/oxm"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans	http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
		http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">


해결방법을 알았다.


Spring Framework의 버전이 3.1.2 인데, Spring 설정 파일에 spring-util-3.2.xsd 라고 되어 있는게 미심쩎어서 

http://www.springframework.org/schema/util/spring-util-3.1.xsd 으로 바꾸었더니 인터넷이 연결 안된 Offline 에서도 잘 구동되었다.


xsd 파일이 jar 파일 안에 저장되어 있는데, Spring 버전이 3.1 이라서 3.1용 xsd 파일만 jar 파일 안에 들어있어서 3.2용 xsd 파일은 찾지 못해서 인터넷으로 찾으려고 했고, 따라서 인터넷이 안되는 Offline 에서는 에러를 냈던 것이다.


[참고] http://stackoverflow.com/questions/1729307/spring-schemalocation-fails-when-there-is-no-internet-connection


Tomcat 이 뜰 때 console 에 다음과 같은 로그가 나오는데, URL의 xsd 파일과 classpath 안의 xsd 파일을 매핑시킨다.



Comments