예제를 보고 또다른 예제를 생성하고 스프링 셋팅 도중 오류가 터졌다.
심각: StandardWrapper.Throwable
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 65 in XML document from ServletContext resource [/WEB-INF/spring-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 65; columnNumber: 16; cvc-complex-type.2.4.a: 'interceptors' 요소로 시작하는 부적합한 콘텐츠가 발견되었습니다. '{"http://www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "http://www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/schema/beans"], "http://www.springframework.org/schema/beans":beans}' 중 하나가 필요합니다.
읽어보면, 스프링 셋팅을 위해 spring-servlet.xml에 넣은 interceptors를 가리키고 있다.
1 2 3 4 5 6 | <interceptors> <interceptor> <mapping path="/{id}/admin"></mapping> <bean class="com.javaex.interceptorex.admin.AdminInterceptor"></bean> </interceptor> </interceptors> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // 복사해서 가져온 예제의 bean <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> // 현재 적용한(오류 발생한) 예제의 bean <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd" xmlns:mvc="http://www.springframework.org/schema/mvc"> | cs |
보기 어렵지만, 중요한 포인트는
복사해서 가져온 예제는 xsi:schemaLocation="http://www.springframework.org/schema/mvc"
현재 오류가 발생한 예제는 xmlns:mvc="http://www.springframework.org/schema/mvc" 이 되어 있는 것이 다르다.
위 예제는 단순히 interceptors를 불렀지만, 아래 예제는 schema/mvc 를 mvc라는 ns에서 쓰겠다고 선언해놓았으므로 interceptors는 mvc 아래에 정의되어 있는 것이다. 위와 같은 경우에는 앞에 mvc: 를 붙여주면 해결된다.
1 2 3 4 5 6 | <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/{id}/admin"></mvc:mapping> <bean class="com.javaex.interceptorex.admin.AdminInterceptor"></bean> </mvc:interceptor> </mvc:interceptors> | cs |