修改spring配置文件的路径

1. spring配置文件的默认路径: /WEB-INF/[servlet-name]-servlet.xml

  <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>

这时,配置文件的名字为:spring-servlet.xml


2. 修改默认文件

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/root-context.xml</param-value>
</context-param>
<servlet>
  <servlet-name>dispatcher</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value></param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>dispatcher</servlet-name>
  <url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

这时名称:root-context.xml

总结:param-value 可以修改配置文件的名称

<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/root-context.xml</param-value>
</context-param>


你可能感兴趣的:(spring,配置文件,Dispatch)