0

I use Apache Tomcat 7 and it's ON - Spring 3 with all the libraries on the classpath (compile and runtime).

that's my web.xml file in /WEB-INF/web.xml:

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

<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

That's my context file in WEB-INF/dispatcherServlet-context.xml:

<!-- Scans within the base package of the application for @Components to configure as beans -->
<context:component-scan base-package="controllers" />

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/views/" />
    <property name="suffix" value=".jsp" />
</bean>

the Tomcat error when i put http://localhost:8080/projectname/ in the browser is:

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml]; 

nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/dispatcherServlet-servlet.xml] ecc ecc ecc

note that the error concern the file dispatcherServlet-servlet.xml not the dispatcherServlet-context.xml (the one i use, created, and mapped)

Thank you all guys!

2 Answers 2

2

In Spring MVC the default location for a dispatcher servlet config is: /WEB-INF/[SERVLET-NAME]-servlet.xml. You can reconfigure this by adding an init parameter to your servlet declaration:

<servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            [PATH-TO-YOUR-FILE]/[CONFIG-FILE-NAME].xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
Sign up to request clarification or add additional context in comments.

1 Comment

apr 12, 2013 5:16:56 PM org.apache.catalina.core.ApplicationContext log INFO: No Spring WebApplicationInitializer types detected on classpath apr 12, 2013 5:16:56 PM org.apache.catalina.core.ApplicationContext log INFO: Initializing Spring FrameworkServlet 'dispatcherServlet'
1

Just remove

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

snippet and rename your dispatcherServlet-context.xml to dispatcherServlet-servlet.xml. Cause: there are two different config files for Spring and Spring MVC. You have tried to use Spring MVC config by Spring Framework.

So for Spring : pass how many you want config files via `contextConfigLocation`
For Spring MVC : /WEB-INF/<dispatcher_servlet_name>-servlet.xml.

You can change default name for Spring MVC case (see @Stefan Lindenberg answer)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.