Announcement Announcement Module
No announcement yet.
Beginner's problem: Servlet is not available Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Beginner's problem: Servlet is not available

    I am getting into Spring, using Spring - A Developer's Notebook updated version (based on Spring 1.1). My environment: Windows XP SP2, JDK 1.6.0-03, Ant 1.7.0, Tomcat 6.0.16, Spring 2.5.

    I cannot get the first "real" Spring example to run (chapter 2, 2nd lab: First use of DispatcherServlet):
    • jars in WEB-INF/lib: spring, spring-webmvc, standard, jstl
    • web.xml: servlet-name set to "rentaBikeApp", servlet-mapping set to "*.bikes" - see below
    • rentaBikeApp-servlet.xml: bean id set to "rentaBike", controllers according to example - see below
    • Tomcat deployment directory: rentabike


       <bean id="rentaBike" class="com.springbook.ArrayListRentABike">
          <property name="storeName"><value>Bruce's Bikes</value></property>
       <bean id="bikesController" class="com.springbook.BikesController">
          <property name="facade"><ref bean="rentaBike"/></property>
       <bean id="editBikeController" class="com.springbook.EditBikeController">
          <property name="facade"><ref bean="rentaBike"/></property>
       <bean id="submitBikeController" class="com.springbook.SubmitBikeController">
          <property name="facade"><ref bean="rentaBike"/></property>
       <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
          <property name="mappings">
                <prop key="/bikes.bikes">bikesController</prop>
                <prop key="/editBike.bikes">editBikeController</prop>
                <prop key="/newBike.bikes">editBikeController</prop>
                <prop key="/submitBike.bikes">submitBikeController</prop>
    On http://localhost:8080/rentabike/bikes.bikes, Tomcat returns the error message "Servlet rentaBikeApp is not available". It appears that rentaBikeApp-servlet cannot be found (same error if file is renamed).

    I am running out of ideas... Is there anything special to consider under Spring 2.5 (conventions, defaults)? Any help is much appreciated.

  • #2
    Hi Peter,

    Usually you should see an error in the Tomcat log that indicates why the Servlet is not available. Most of the time, the servlet could not be started because of errors during initialization.

    It might also be a good idea to have a look at the current samples provided with the spring download. I am sure there are some differences between Spring 1.1 and 2.5 that could prevent the application from starting correctly.


    • #3
      Hi Kariem,

      Thank you for your quick response and the helpful hint!

      The Tomcat error log revealed a problem with the logger, and based on the book's errata page I added commons-logging.jar and log4j-1.2.14.jar to WEB-INF/lib (I did not even configure the logger), and there is no more Tomcat error

      There are still some glitches (I guess with the tag library) which I will have to investigate, but the main problem is gone.

      Thanks again, your help saved me a lot of time!


      • #4
        getting spring security demo to work

        Besides adding the mention jars to the classpath (log4j and commons-logging), I also had this error:

        SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener
        java.lang.IllegalStateException: Cannot set web app root system property when WAR file is not expanded

        After exploding the war also, the demo worked.

        Paul Sundling


        • #5
          more possible issues

          Forgot to mention that if you deployed the war first before exploding it, you may also need to remove that and restart tomcat before things will work. Everything is the same for both


          Also here is the original error I got in Tomcat manager that started me down the rabbit hole:

          FAIL - Application at context path /spring-security-samples-contacts-2.0.3 could not be started

          Paul Sundling


          • #6
            Servlet DemoClass is not available


            I have created a java class "DemoClass" in netbeans.specified the servlet and servlet-mapping in web.xml.but when i run the class it shows Servlet DemoClass is not available. please help asap .