Announcement Announcement Module
Collapse
No announcement yet.
Don't work component-scan RequestMapping Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <display-name>AppSpringJ2EE</display-name>

    <servlet>
    <servlet-name>AppSpring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/configure/AppSpring-servlet.xml</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>AppSpring</servlet-name>
    <url-pattern>/*</url-pattern>
    </servlet-mapping>

    </web-app>

    AppSpring-servlet.xml

    <?xml version="1.0" encoding="utf-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.5.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

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

    </beans>

    And controller classes:

    package myjavaclasses.servlet;

    import java.io.IOException;
    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;

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

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

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

    @RequestMapping("/sesion/index")
    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 /0.0.0.0:8009
    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
    Hello

    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

    Comment


    • #3
      What view resolver do you have registered?

      Comment


      • #4
        solved

        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.

        Comment

        Working...
        X