Skip to main content
The 2024 Developer Survey results are live! See the results
added 104 characters in body
Source Link
Hunter Zhao
  • 4.6k
  • 2
  • 27
  • 39

What is the difference between the contextConfigLocation and namespace? contextConfigLocation is used to specify the path of spring config files, that means they'll be initialized. namespace is used to specify the path and name of the DispatcherServlet of Spring MVC. default is [Dispatcher_name]-servlet.xml[Dispatcher_name]-servlet.xml, here is an example:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>namespace</param-name>
        <param-value>config/spring-mvc</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Spring will search a file to be used as it's mvc config by the path of /WEB-INF/config/spring-mvc.xml/WEB-INF/config/spring-mvc.xml.
Is the contextConfigLocation meant only for specifying the folders where the context class can find a XML definition

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/app-*.xml</param-value>
</context-param>

The code above showed that when application starting Spring will load all the the files which name starts with 'app-' and ends with '.xml' in the WEB-INF/config directory.

Should it use /WEB-INF/application-context.xml? And should you specify paths?
Through the first example all above we can know that when configurating Spring we need to specify the full path and generic file name and when SpringMVC only we should specify the path(if it's located in a directory, not include the WEB-INF directory) and name(not include the extension).
Hope to help you:)

What is the difference between the contextConfigLocation and namespace? contextConfigLocation is used to specify the path of spring config files, that means they'll be initialized. namespace is used to specify the path and name of the DispatcherServlet of Spring MVC. default is [Dispatcher_name]-servlet.xml, here is an example:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>namespace</param-name>
        <param-value>config/spring-mvc</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Spring will search a file to be used as it's mvc config by the path of /WEB-INF/config/spring-mvc.xml.
Is the contextConfigLocation meant only for specifying the folders where the context class can find a XML definition

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/app-*.xml</param-value>
</context-param>

The code above showed that when application starting Spring will load all the the files which name starts with 'app-' and ends with '.xml' in the WEB-INF/config directory.

Should it use /WEB-INF/application-context.xml? And should you specify paths?
Through the first example we can know that only we should specify the path(if it's located in a directory, not include the WEB-INF directory) and name(not include the extension)

What is the difference between the contextConfigLocation and namespace? contextConfigLocation is used to specify the path of spring config files, that means they'll be initialized. namespace is used to specify the path and name of the DispatcherServlet of Spring MVC. default is [Dispatcher_name]-servlet.xml, here is an example:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>namespace</param-name>
        <param-value>config/spring-mvc</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Spring will search a file to be used as it's mvc config by the path of /WEB-INF/config/spring-mvc.xml.
Is the contextConfigLocation meant only for specifying the folders where the context class can find a XML definition

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/app-*.xml</param-value>
</context-param>

The code above showed that when application starting Spring will load all the the files which name starts with 'app-' and ends with '.xml' in the WEB-INF/config directory.

Should it use /WEB-INF/application-context.xml? And should you specify paths?
Through the example all above we can know that when configurating Spring we need to specify the full path and generic file name and when SpringMVC only we should specify the path(if it's located in a directory, not include the WEB-INF directory) and name(not include the extension).
Hope to help you:)

Source Link
Hunter Zhao
  • 4.6k
  • 2
  • 27
  • 39

What is the difference between the contextConfigLocation and namespace? contextConfigLocation is used to specify the path of spring config files, that means they'll be initialized. namespace is used to specify the path and name of the DispatcherServlet of Spring MVC. default is [Dispatcher_name]-servlet.xml, here is an example:

<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>namespace</param-name>
        <param-value>config/spring-mvc</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

Spring will search a file to be used as it's mvc config by the path of /WEB-INF/config/spring-mvc.xml.
Is the contextConfigLocation meant only for specifying the folders where the context class can find a XML definition

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/config/app-*.xml</param-value>
</context-param>

The code above showed that when application starting Spring will load all the the files which name starts with 'app-' and ends with '.xml' in the WEB-INF/config directory.

Should it use /WEB-INF/application-context.xml? And should you specify paths?
Through the first example we can know that only we should specify the path(if it's located in a directory, not include the WEB-INF directory) and name(not include the extension)