아무것도 모르고 단순히 applicationContext의 경로만 지정;;
이 경우 서블릿에서 디폴트로 서블릿 설정 파일을 바라본다.
- [서블릿이름-Servlet.xml]
당연히 위 이름대로 선언된 파일이 없으니 에러가 난다.
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/MyRoad-servlet.xml]
커스텀하게 변경할 수 있는데 이것이 바로 init-param이다.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/context/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>MyRoad</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/context/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyRoad</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
참고
- http://viralpatel.net/blogs/change-spring-servlet-filename-configuration/