springMVC的配置文件路径问题
[转载] https://www.cnblogs.com/imperfectLiu/articles/7299299.html
第一:加载web.xml之后,读哪个配置文件问题?即是applicationContext.xml还是xxx-servlet.xml?
解答:①在web.xml中配置DispatcherServlet时,看下面代码红色
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
</servlet>
在没有
即是:dispatch-servlet.xml
②:如果有
第二:如果配置了,那么applicationContext.xml文件在哪里?
解答:下面第一种方式,在/WebContent/WEB-INF/目录下
第二种方式,在/src/目录下
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
</servlet>
浙公网安备 33010602011771号