-
Jul 28th, 2011, 02:16 PM
#1
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!!
-
Jul 29th, 2011, 07:01 PM
#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
- Manuel Jordan
Kill Your Pride, Share Your Knowledge With All
The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7
Blog
Technical Reviewer of Apress
- Pro SpringSource dm Server
- Spring Enterprise Recipes: A Problem-Solution Approach
- Spring Recipes: A Problem-Solution Approach, 2nd Edition
- Pro Spring Integration
- Pro Spring Batch
- Pro Spring 3
- Pro Spring MVC: With Web Flow
- Pro Spring Security
-
Aug 1st, 2011, 07:16 AM
#3
What view resolver do you have registered?
-
Aug 3rd, 2011, 04:24 PM
#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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules