user3263992
user3263992

Reputation: 53

Spring servlet in web.xml with missing contextConfigLocation param-value

I have a web.xml file with (among other things) a servlet that defines an init-param to specify the contextConfigLocation, but the param-value is BLANK?

Why is the developer doing this. I can't for the life of me find anything in the documentations for Spring 3.X that tells me what effect this has.

<servlet>
    <servlet-name>restservices</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>

Upvotes: 4

Views: 2648

Answers (3)

M. Deinum
M. Deinum

Reputation: 124441

By default the DispatcherServlet will load a xml file named [servlet-name]-servlet.xml.

This is when no init-param named contextConfigLocation is defined.

However in your case there is an init-param named contextConfigLocation defined, which tells the DispatcherServlet to load nothing but only delegate to the parent context (the one loaded by the ContextLoaderListener).

So in short there is a difference between no init-param defined or an empty init-param.

See also https://jira.springsource.org/browse/SPR-4746.

Upvotes: 5

Hrishikesh
Hrishikesh

Reputation: 2053

Ah. Generally, the dispatcher servlet would follow the convention of searching for servlet-name - servlet.xml to load the WebAppContext. It might be (and this is just guess work because i dont know your config) that there already is a file restservices-servlet.xml which is

  • loaded using the ContextLoaderListener
  • Or imported in your applicationContext.xml ( or its equivalent)
  • Or isnt needed, because all the beans for the Controller/ViewResolver are configured in your applicationContext.xml

Typically, the DispatcherServlet config (WebappContext) should contain the Controller/ViewResolver bean definitions.

Upvotes: 0

storm_buster
storm_buster

Reputation: 7568

it just because the developer had nothing to declare in the servlet configuration. he had maybe defined all what he needs in the root context.

Upvotes: 1

Related Questions