Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Servlet and URL Mapping doubts - HTTP 404

  1. #11
    Join Date
    Aug 2010
    Posts
    20

    Default Part XI (relevant, too)

    I won't include all of them but seems that there is a log event for every URL match, like my beloved /WEB-INF/views/home.jsp:

    Code:
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvc-showcase/]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/] to HandlerExecutionChain with handler [org.springframework.web.servlet.mvc.ParameterizableViewController@56d99277] and 2 interceptors
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/mvc-showcase/] is: -1
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'home'; URL [/WEB-INF/views/home.jsp]] in DispatcherServlet with name 'appServlet'
    DEBUG: org.springframework.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/views/home.jsp] in InternalResourceView 'home'
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvc-showcase/resources/form.css]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/form.css] are [/resources/**]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/form.css] are {}
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/form.css] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@372eabae] and 2 interceptors
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/mvc-showcase/resources/form.css] is: -1
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Trying relative path [form.css] against base location: ServletContext resource [/resources/]
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Found matching resource: ServletContext resource [/resources/form.css]
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Determined media type [text/css] for ServletContext resource [/resources/form.css]
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Resource not modified - returning 304
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'appServlet': assuming HandlerAdapter completed request handling
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvc-showcase/resources/jqueryui/1.8/themes/base/jquery.ui.all.css]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/jqueryui/1.8/themes/base/jquery.ui.all.css] are [/resources/**]
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvc-showcase/resources/jquery/1.4/jquery.js]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/jquery/1.4/jquery.js] are [/resources/**]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/jquery/1.4/jquery.js] are {}
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/jquery/1.4/jquery.js] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@372eabae] and 2 interceptors
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/mvc-showcase/resources/jquery/1.4/jquery.js] is: -1
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/jqueryui/1.8/themes/base/jquery.ui.all.css] are {}
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/jqueryui/1.8/themes/base/jquery.ui.all.css] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@372eabae] and 2 interceptors
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/mvc-showcase/resources/jqueryui/1.8/themes/base/jquery.ui.all.css] is: -1
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvc-showcase/resources/jqueryform/2.4/jquery.form.js]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/jqueryform/2.4/jquery.form.js] are [/resources/**]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/jqueryform/2.4/jquery.form.js] are {}
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/jqueryform/2.4/jquery.form.js] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@372eabae] and 2 interceptors
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/mvc-showcase/resources/jqueryform/2.4/jquery.form.js] is: -1
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvc-showcase/resources/jqueryui/1.8/jquery.ui.core.js]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Matching patterns for request [/resources/jqueryui/1.8/jquery.ui.core.js] are [/resources/**]
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'appServlet' processing GET request for [/mvc-showcase/resources/jqueryui/1.8/jquery.ui.widget.js]
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - URI Template variables for request [/resources/jqueryui/1.8/jquery.ui.core.js] are {}
    DEBUG: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/resources/jqueryui/1.8/jquery.ui.core.js] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@372eabae] and 2 interceptors
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/mvc-showcase/resources/jqueryui/1.8/jquery.ui.core.js] is: -1
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Trying relative path [jqueryui/1.8/jquery.ui.core.js] against base location: ServletContext resource [/resources/]
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Found matching resource: ServletContext resource [/resources/jqueryui/1.8/jquery.ui.core.js]
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Determined media type [text/javascript] for ServletContext resource [/resources/jqueryui/1.8/jquery.ui.core.js]
    DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - Resource not modified - returning 304
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'appServlet': assuming HandlerAdapter completed request handling
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    (Continues...)

  2. #12
    Join Date
    Aug 2010
    Posts
    20

    Default Part XII - And finally, MY log (shorter)

    Log for my project:

    Code:
    19-ago-2010 10:40:53 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: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
    19-ago-2010 10:40:53 org.apache.tomcat.util.digester.SetPropertiesRule begin
    ADVERTENCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:carrerer' did not find a matching property.
    19-ago-2010 10:40:53 org.apache.coyote.http11.Http11Protocol init
    INFO: Inicializando Coyote HTTP/1.1 en puerto http-8080
    19-ago-2010 10:40:53 org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 793 ms
    19-ago-2010 10:40:53 org.apache.catalina.core.StandardService start
    INFO: Arrancando servicio Catalina
    19-ago-2010 10:40:53 org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
    19-ago-2010 10:40:54 org.apache.catalina.core.ApplicationContext log
    INFO: Set web app root system property: 'carrerer.root' = [/Users/lserrano/Documents/workspace-sts-2.3.2.RELEASE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/carrerer/]
    19-ago-2010 10:40:54 org.apache.catalina.core.ApplicationContext log
    INFO: Initializing log4j from [/Users/lserrano/Documents/workspace-sts-2.3.2.RELEASE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/carrerer/WEB-INF/etc/log4j.xml]
    19-ago-2010 10:40:54 org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    DEBUG JdbcTemplateCarrererMaintenanceService - JdbcTemplateCarrererService()
    DEBUG JdbcTemplateCarrererMaintenanceService - JdbcTemplateCarrererService()
    DEBUG JdbcTemplateCarrererMaintenanceService - JdbcTemplateCarrererMaintenanceService()
    19-ago-2010 10:40:55 org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring FrameworkServlet 'appServlet'
    19-ago-2010 10:40:55 org.apache.coyote.http11.Http11Protocol start
    INFO: Arrancando Coyote HTTP/1.1 en puerto http-8080
    19-ago-2010 10:40:56 org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8009
    19-ago-2010 10:40:56 org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/84  config=null
    19-ago-2010 10:40:56 org.apache.catalina.startup.Catalina start
    INFO: Server startup in 2725 ms
    As you can see, both show this message:

    INFO: Initializing Spring FrameworkServlet 'appServlet'
    but the first log (the huge one in previous replies) makes me think that something is going on, whilst mine seems like a sad deserted call in the middle of nowhere, resulting in no effect whatsoever

    Well, if anyone has done it until here, thank you already for reading.

    Any tip or help would be greatly appreciated. Please bear in mind that I am quite new to all the Spring goodness, and I am still in need of a touch of gentleness when talking of details about configurations, controllers, annotations, AutoWired and the rest of such spring-ly vocabulary (plus English is not my primary language, which makes the writting of this post a bit funnier).

    Thank you in advance!!!

    Luis Serrano
    Barcelona - Spain

    Servlet and URL Mapping doubts - HTTP 404
    mapping, DispatcherServlet, web.xml, 404 error, JSP

  3. #13
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Hola,

    I think I located the source of your problems. In your appServlet-servlet.xml, try to add the following line:

    Code:
    <mvc:annotation-driven/>
    Also, put all bean definitions of classes annotated with @Controller inside this file. The way you are configuring things now, your controllers aren't being scanned at all.

    I also noted many more incongruencies and oddities in your configuration (e.g. you probably didn't understand at all the concept of separation between core Spring config loaded with listener and Spring web mvc config loaded with DispatcherServlet context-param), which makes me suggest you need to study a little bit more the Spring documentation and try simple examples before building something complex like you are trying to do.

  4. #14
    Join Date
    Aug 2010
    Posts
    20

    Default

    Thank you Enrico,

    I added this:

    Code:
    <mvc:annotation-driven/>
    before your reply, because I saw it somewhere. It still makes no difference, although adding this:

    Code:
    	<!-- Maps '/' requests to the 'home' view -->
    	<mvc:view-controller path="/" view-name="home"/>
    	
    	<context:component-scan base-package="com.grupogodo.it.projects.carrerer.web" />
    	<context:annotation-config/>
    now allows me to see the "home" view when I access my application root URL. It doesn't work if I specify the "home" view myself, or other views, which makes me think I haven`t fixed anything just yet.

    By the way, you suggested that by adding this:

    Code:
    <context:component-scan base-package="com.grupogodo.it.projects.carrerer.web" />
    	<context:annotation-config/>
    I should be adding the beans definition to appServlet-servlet.xml. I've done that, like this:
    Code:
    	<beans:bean id="SimpleController" class="com.grupogodo.it.projects.carrerer.web.SimpleController">
    	</beans:bean>
    And I have created such class within the specified package:

    Code:
    package com.grupogodo.it.projects.carrerer.web;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    @RequestMapping(value="/simple/*")
    public class SimpleController {
    
    	@RequestMapping(value="/prueba", method=RequestMethod.GET)
    	public String simple() {
    		return "Controlador simple!!";
    	}
    
    }
    But it results in a ClassNotFoundException:

    Code:
    GRAVE: StandardWrapper.Throwable
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.grupogodo.it.projects.carrerer.web.SimpleController] for bean with name 'SimpleController' defined in ServletContext resource [/WEB-INF/system/config/appServlet-context.xml]; nested exception is java.lang.ClassNotFoundException: com.grupogodo.it.projects.carrerer.web.SimpleController
    Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.grupogodo.it.projects.carrerer.web.SimpleController] for bean with name 'SimpleController' defined in ServletContext resource [/WEB-INF/system/config/appServlet-context.xml]; nested exception is java.lang.ClassNotFoundException: com.grupogodo.it.projects.carrerer.web.SimpleController
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:574)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
    	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
    	at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
    	at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
    	at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    	at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    	at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
    	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
    	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    	at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
    	at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    I am not sure whether it is required to define that bean in this file, I haven't seen it in the examples I've read.

    Any idea?

  5. #15
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    1) mvc:annotation-driven SUBSTITUTES context:component-scan for controllers; thus in a correct configuration you should have mvc:annotation-driven in your dispatcherservlet-specific file (i.e. the webmvc config) AND (optionally) a context:component-scan directive in the Spring core main configuration (i.e. the non-mvc related) which scans packages OTHER than controller packages for other annotations like @Service, @Transactional etc (if you don't exclude your controller packages, the controllers will get scanned twice). mvc:annotation-driven is far better than simple component scan for controllers since it gives you full web mvc configuration in just one line;

    2) annotation-driven and component-scan will only scan for classes inside the application context. If you don't register a class as a Spring bean with the <bean> tag in the correct xml config file, you can put all annotations you want inside it, but Spring will simply ignore them. Thus, you must register ALL your controllers as Spring beans in the correct xml (the one loaded by DispatcherServlet) or else they won't be controllers (in fact they won't ever be part of your context and you won't be able to use them; don't you use dependency injection to inject services etc in your controllers? If not, you really haven't understood what Spring is).

    I could go on like forever, but I just can't condensate a full Spring lesson in a forum thread, so I strongly suggest you start studying books & documentation about Spring before you try to set up your own complex project by copying from examples you don't understand...

  6. #16
    Join Date
    Aug 2010
    Posts
    20

    Default Thank you

    Dear Enrico.

    As I said in the beginning, I am quite new to Spring, but I am not new to programming and also I don't think I am that far from getting it working. So you don't need to go on forever, really.

    I am not asking lightly, I have read enough and I try to understand things instead of just hitting ctrl+c, ctrl+v... What I am doing, as you said, is a complex thing and that's why I am asking here. If it was easy I'd probably manage myself.

    Thank you anyway for taking the time of answering.

  7. #17
    Join Date
    Aug 2010
    Posts
    20

    Default

    I think this answers my doubts about component-scanning:
    http://forum.springsource.org/member.php?u=45487

    I have advanced quite a lot, I have succesfully configured a test project and now @Controllers get scanned and they respond to the URL specified in @RequestMapping("/whatever").

    However there are still a few things I don't get. As Enrico said, I probably should investigate a bit more about "the concept of separation between core Spring config loaded with listener and Spring web mvc config loaded with DispatcherServlet context-param", which may be preventing my target project from serve both the original Web Services and the mapped-to-@Controller URL's.

    Thank you,

    Luis
    Last edited by Moonwalker; Aug 20th, 2010 at 02:34 AM.

  8. #18
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    It is quite simple actually. When using Spring in a web application, you will have one CORE context containing everything non servlet-related (everything that is not web related: services, daos, pojos, aspects etc). This context is loaded by adding the following in web.xml:

    Code:
      <listener>
    	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
      
      <context-param>
    	<param-name>contextConfigLocation</param-name>
    	<param-value>/WEB-INF/core-context.xml</param-value>
      </context-param>
    Then, you will have one more context for each Spring servlet you load in web.xml, for example if you use DispatcherServlet (Spring's web mvc):

    Code:
      <servlet>
    	<servlet-name>dispatcher</servlet-name>
    	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    	<init-param>
    	  <param-name>contextConfigLocation</param-name>
    	  <param-value>WEB-INF/dispatcher-context.xml</param-value>
    	</init-param>
    	<load-on-startup>1</load-on-startup>
      </servlet>
    
      <servlet-mapping>
    	<servlet-name>dispatcher</servlet-name>
    	<url-pattern>*.htm</url-pattern>
      </servlet-mapping>
    You will need one more context since you are also using Spring's web services.

    What about relations between those context? Well the core context will be at the disposal of every other servlet-loaded context. This means, for example, that you can inject and use core beans like services and daos inside your controllers.
    On the other hand, the reverse is not true: you can't inject beans from your web mvc context inside your core context, but why should you do something like that really? It's controllers that call services and not vice-versa!
    Also, your servlet context won't interact with each other, so, for example, you can't inject a controller inside a web service or vice-versa (again, why would you ever need to do something like that?)

    Hope I was clear enough...

  9. #19
    Join Date
    Aug 2010
    Posts
    20

    Default Interesting

    Thank you Enrico, what you said sounds good to me. But maybe I could do it better by serving my Web Services using Spring MVC annotations, couldn't I?

    Our services are SOAP based -not REST-, so I don't know yet if it's supported.

    Spring 3.0 REST services are explained quite well here:
    http://www.oudmaijer.com/blog/2010/0...th-spring-mvc/

    (not my goal but maybe someone was after it).

    Cheers,

  10. #20
    Join Date
    Aug 2010
    Posts
    20

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
  •