Results 1 to 9 of 9

Thread: Diff in Spring MVC 3.0 & 2.5 @RequestMapping behavior

  1. #1
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Question Diff in Spring MVC 3.0 & 2.5 @RequestMapping behavior

    I've found a difference in the behavior of Spring MVC with respect to @RequestMapping annotations -- in Spring 3.0.2.RELEASE, the following example works, but against Spring 2.5.6.SEC01, the exact same controller code and configuration (except for the change in Spring dependencies) is broken, resulting in "No mapping found for HTTP request with URI" error messages.

    Here's my sole context configuration file (yes, using the 2.5 XSDs in both the Spring 3 and Spring 2.5 tests):
    Code:
    <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/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
    
        <context:component-scan base-package="org.example.springmvctest" />
    
        <bean
            class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
    
        <bean
            class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/views/" />
            <property name="suffix" value=".jsp" />
        </bean>
    
    </beans>
    And my controller class:
    Code:
    @Controller
    @RequestMapping("/abc")
    public class SampleController {
    
        @RequestMapping("/def")
        public String myMethod(Model model) {
        model.addAttribute("thing", "myMethod");
        return "xyz";
        }
    
        @RequestMapping("/ghi")
        public String myOtherMethod(Model model) {
        model.addAttribute("thing", "myOtherMethod");
        return "xyz";
        }
    }
    And my jsp view template "WEB-INF/views/xyz.jsp":
    Code:
    Thing is ${thing}
    When I run my webapp against Spring 3.0.2.RELEASE, everything works fine. When I run the exact same code & context config file against Spring 2.5.6.SEC01, I get the HandlerMapping error:
    Code:
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' determining Last-Modified value for [/blargy/app/abc/ghi]
    DEBUG: org.springframework.web.servlet.DispatcherServlet - No handler found in getLastModified
    DEBUG: org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing request for [/blargy/app/abc/ghi]
    WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/blargy/app/abc/ghi] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet'
    DEBUG: org.springframework.web.servlet.DispatcherServlet - Successfully completed request
    What gives? What additional context configuration do I need to add to Spring 2.5 in order to make it work, given that it works as is against Spring 3?

    -matthew
    Last edited by matthewadams; May 26th, 2010 at 05:17 PM. Reason: omission of view template name

  2. #2

    Default

    check the url you are requesting...and try to useorg.springframework.web.servlet.mvc.support.Con trollerClassNameHandlerMapping...by which we can access the jsp pages based upon the name...

    hope it will work...if not just tell me whats the url you are using to get the output.

  3. #3
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default

    I don't think that's going to help me, as I'm using @Controller-annotated controllers with @RequestMapping annotations on the type and on the methods.

    BTW, the URLs are evident in the log: /blargy/app/abc/def & /blargy/app/abc/ghi

  4. #4

    Default

    can you please paste your servlet-mapping url-pattern code from web.xml...

    let me check how you have written that

  5. #5
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default

    My projects are straight from the "Spring MVC Project" template that's available in SpringSource Tool Suite 2.3.2.

    web.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
        <!-- Enables clean URLs with JSP views e.g. /welcome instead of /app/welcome -->
        <filter>
            <filter-name>UrlRewriteFilter</filter-name>
            <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>UrlRewriteFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
            
        <!-- Handles all requests into the application -->
        <servlet>
            <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>
                    /WEB-INF/spring/*.xml
                </param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>
            
        <!-- Maps all /app requests to the DispatcherServlet for handling -->
        <servlet-mapping>
            <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
            <url-pattern>/app/*</url-pattern>
        </servlet-mapping>
        
    </web-app>
    urlrewrite.xml:
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN" "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
    <urlrewrite default-match-type="wildcard">
        <rule>
            <from>/</from>
            <to>/app/welcome</to>
        </rule>
        <rule>
            <from>/**</from>
            <to>/app/$1</to>
        </rule>
        <outbound-rule>
            <from>/app/**</from>
            <to>/$1</to>
        </outbound-rule>    
    </urlrewrite>

  6. #6
    Join Date
    Jul 2005
    Location
    Austin, TX
    Posts
    137

    Default Filed bug with reproducible test case


  7. #7
    Join Date
    Aug 2006
    Posts
    144

    Default

    It is almost a year later. The bug report shows "no work". Has anybody figured out the cause for this issue?

    Are annotated @RequestMapping just plain broken in 2.5.6?

    Needless to say, I am experiencing the same problem. The app works perfectly on a server with Spring 3.0.x but fails miserably in a server with Spring 2.5.6, giving the error:
    Code:
    [org.springframework.web.servlet.PageNotFound] No mapping found for HTTP request with URI [/MyApp/home/list.htm] in DispatcherServlet with name 'MyApp'

  8. #8

    Default

    same thing happen to me. should be give up spring 2.5

  9. #9
    Join Date
    Aug 2006
    Posts
    144

    Default

    Quote Originally Posted by jimmy6 View Post
    same thing happen to me. should be give up spring 2.5
    Would love nothing better than give up on 2.5.

    Unfortunately, Spring 3.0 isn't 100% backward compatible (they changed the package structure in Spring Security). Thus upgrading requires making changes to the apps.

    So our old servers are stuck at 2.5 until every application is modified and migrated to 3.0... in a new server. A very long process and a royal pain in the tush.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •