초급의 끄적거림

[Spring] 오류 'mvc:annotation-driven' 요소에 대한 선언을 찾을 수 없습니다. 본문

Framework/Spring

[Spring] 오류 'mvc:annotation-driven' 요소에 대한 선언을 찾을 수 없습니다.

codingD 2021. 4. 14. 21:34

오류문구

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from ServletContext resource [/WEB-INF/dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 30; cvc-complex-type.2.4.c: 일치하는 와일드 카드 문자가 엄격하게 적용되지만 'mvc:annotation-driven' 요소에 대한 선언을 찾을 수 없습니다.

 

원인


  • dispatcher-servlet.xml 에 xmlns:mvc 와 xmlns:context 를 추가한 후에 xsi:schemaLocation 에 동일한 해당 경로를 추가해주어야 하는데 추가 하지 않음
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"

 

해결방법


  • 해당 경로와 일치하도록 추가 진행
<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">

    <mvc:annotation-driven />
    <context:component-scan base-package="my.payment.controller" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

 

 

Comments