Monday, 28 February 2011

A Fix to Our Spring-MVC Course

Just a quick blog post to alert that there is an error in one of the config files in the Spring-MVC course. I'm uploading a fixed version now, so if you're a user of the course, please download the new "Practicals and Code" folder, or follow these instructions:

If you start your project from the "Starting Code" folder, our web.xml contains the following:

   <!--  we've already configured Spring-MVC for you - nothing to do here! -->         
    <servlet>
       <servlet-name>FrontController</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>
  
    <servlet-mapping>
       <servlet-name>FrontController</servlet-name>
       <url-pattern>*.do</url-pattern>
    </servlet-mapping>

However, our Spring XML config file is called "Dispatcher-servlet.xml".

By default, Spring finds it's config file in a web app by taking the servlet name and appending "-servlet.xml" to the end - it then looks for a matching file in /WEB-INF.

If you downloaded the course before the date of this post, please rename the servlet name to Dispatcher (it appears twice in web.xml).

So, your web.xml file should be (in full):

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
         
    <!--  we've already configured Spring-MVC for you - nothing to do here! -->         
    <servlet>
       <servlet-name>Dispatcher</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>
  
    <servlet-mapping>
       <servlet-name>Dispatcher</servlet-name>
       <url-pattern>*.do</url-pattern>
    </servlet-mapping>

</web-app>


Many apologies for the inconvenience this has caused - it was entirely my fault and happened because I changed my naming convention between chapters.

Thanks to David Wubshet and Benjamin Quarless amongst others for flagging up this problem.

3 comments:

  1. Can you send the Sample programs for Servlet using Session concepts?

    Cegonsoft

    ReplyDelete
  2. Hi Richard,

    I acquired all your courses recently. I was very satisfied and learned a lot from the Spring Fundamentals one. I am having problems with the MVC one. I am getting the following error:

    java.lang.IllegalStateException: Cannot map handler [/viewAllBooks.do] to URL path [/viewAllBooks]: There is already handler [com.virtualpairprogrammers.control.ViewAllBooksController@5106def2] mapped.

    Looking at the full stack trace there may be something happening with the Autowiring behavior of Spring. How can I get help on this?

    Thanks,

    - Alberto.

    ReplyDelete
  3. Hi Alberto,

    Best thing to do is to send a support request in through the "contact" form on the VirtualPairProgrammers.com website. Then we can have a good look at your code. Someone should answer as early as possible on Monday.

    I'm sure it will be an easy fix!

    Cheers,
    Richard.

    ReplyDelete