Announcement Announcement Module
No announcement yet.
Don't work component-scan RequestMapping Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Don't work component-scan RequestMapping

    I'm a new programmer on Spring Framework, i'm learning to use now.

    I've this config:


    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi=""
    id="WebApp_ID" version="2.5">


    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>



    <?xml version="1.0" encoding="utf-8"?>
    <beans xmlns=""

    <!-- The controllers are autodetected POJOs labeled with the @Controller annotation. -->
    <context:component-scan base-package="myjavaclasses.servlet">


    And controller classes:

    package myjavaclasses.servlet;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.springframework.beans.factory.annotation.Autow ired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMap ping;
    import org.springframework.web.servlet.ModelAndView;
    import myjavaclasses.jbeans.SesionAPP;

    @RequestMapping(value = "/sesion/**")
    public class AppServletSesion {

    /* ----------
    * Atributos
    * ---------

    private static final long serialVersionUID = 1L;
    SesionAPP sesionApp;

    public ModelAndView index(ModelMap modelMap)
    throws ServletException, IOException {

    // enviar el bean sesion
    modelMap.addAttribute("sesionApp", sesionApp);

    // preparar la respuesta al sesion.jsp
    return new ModelAndView("/WEB-INF/src/views/sesion.jsp", modelMap);

    But, when I request /localhost:8080/sesion/index, Tomcat don't execute controller Estado HTTP 404 - /sesion/index Resource not avaliable.

    What I do wrong??? Why don't scan-component?

    Console Tomcat Out:
    28-jul-2011 21:09:11 org.apache.catalina.core.AprLifecycleListener init
    INFO: La biblioteca nativa de Apache Tomcat basada en ARP que permite un rendimiento óptimo en entornos de desarrollo no ha sido hallada en java.library.path: /usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386:/usr/lib/jvm/java-6-openjdk/jre/../lib/i386:/usr/lib/jvm/java-6-openjdk/jre/lib/i386/client:/usr/lib/jvm/java-6-openjdk/jre/lib/i386::/usr/java/packages/lib/i386:/usr/lib/i386-linux-gnu/jni:/lib/i386-linux-gnu:/usr/lib/i386-linux-gnu:/usr/lib/jni:/lib:/usr/lib
    28-jul-2011 21:09:12 org.apache.coyote.http11.Http11Protocol init
    INFO: Inicializando Coyote HTTP/1.1 en puerto http-8080
    28-jul-2011 21:09:12 org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 2148 ms
    28-jul-2011 21:09:13 org.apache.catalina.core.StandardService start
    INFO: Arrancando servicio Catalina
    28-jul-2011 21:09:13 org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/6.0.32
    28-jul-2011 21:09:13 org.apache.catalina.startup.HostConfig deployDescriptor
    INFO: Desplieque del descriptor de configuración AppJ2EE.xml
    28-jul-2011 21:09:13 org.apache.coyote.http11.Http11Protocol start
    INFO: Arrancando Coyote HTTP/1.1 en puerto http-8080
    28-jul-2011 21:09:13 org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /
    28-jul-2011 21:09:14 org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/81 config=null
    28-jul-2011 21:09:14 org.apache.catalina.startup.Catalina start
    INFO: Server startup in 1131 ms

    Thank You!!

  • #2

    1) use code tags, is more readable for us
    2) you missing to use <context:annotation-config /> to work with @Controller
    3) Avoid use /WEB-INF/src/views/sesion.jsp and use a ViewResolver instead,
    read carefully the 15. Web MVC framework documentation
    4) you are using the default jdk which comes by default with Linux, right?, I suggest you use the jdk by SUn or Oracle


    • #3
      What view resolver do you have registered?


      • #4

        Thanks to the two.

        I get reply to the Tomcat, now I receive a error from @autowired model, in the acceces to the controller, Spring built the beans and dependencies, and I get error to 'create nested attributes' in controller

        I'm going to investigate why occurs that.

        See you later. Thank you.