Announcement Announcement Module
Collapse
No announcement yet.
Spring migration from 3.0.5 to 3.1.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring migration from 3.0.5 to 3.1.1

    I get handler mapping exception when I simply upgrade from 3.0.5.RELEASE to 3.1.1.RELEASE for the root path. Works perfectly fine in 3.0.5.

    The root URL: http://localhost:8080/hello-world-web/ doesn't work in 3.1.1

    http://localhost:8080/hello-world-web/hello/ works in both.

    Here is a HelloWorld recreation:

    MVC Servlet - hello-world-servlet.xml:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans
    		http://www.springframework.org/schem...-beans-3.0.xsd
    		http://www.springframework.org/schema/context
    		http://www.springframework.org/schem...ontext-3.0.xsd
    		http://www.springframework.org/schema/mvc
    		http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    
    	<context:component-scan base-package="hello.web.controller" />
    	<mvc:annotation-driven />
    
    	<bean id="welcomeMapping"
    		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/">helloWorldController</prop>
    			</props>
    		</property>
    	</bean>
    	
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass"
    			value="org.springframework.web.servlet.view.JstlView" />
    		<property name="prefix" value="/jsp/" />
    		<property name="suffix" value=".jsp" />
    	</bean>
    
    </beans>
    Controller class - HelloWorldController.java

    Code:
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.servlet.ModelAndView;
    
    @Controller
    @RequestMapping("/hello")
    public class HelloWorldController {
    	
    	@RequestMapping(method = { RequestMethod.GET })
    	public ModelAndView getHelloWorld(ModelMap modelMap, HttpServletRequest req)
    			throws ServletException, IOException {
    
    		String aMessage = "Hello World MVC!";
    
    		ModelAndView modelAndView = new ModelAndView("HelloWorld");
    		modelAndView.addObject("message", aMessage);
    
    		return modelAndView;
    	}
    }
    JSP - HelloWorld.jsp

    HTML Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <body>
    	<p>This is my message: ${message}</p>
    </body>
    </html>
    3.0.5.RELEASE DEBUG
    Code:
    12:34:35,616 INFO  [FsaEarDeployer] Started J2EE application: file:/C:/softwaredistribution/jboss-4.2.3.GA/server/hello-world/deploy/hello-world-ear-1.0.ear
    12:34:35,682 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-localhost%2F127.0.0.1-8080
    12:34:35,694 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-localhost%2F127.0.0.1-8009
    12:34:35,700 INFO  [Server] JBoss (MX MicroKernel) [4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)] Started in 15s:815ms
    12:34:56,034 INFO  [STDOUT] [26 Mar 2012 12:34:56,034] DEBUG [DispatcherServlet] DispatcherServlet with name 'hello-world' processing GET request for [/hello-world-web/]
    12:34:56,040 INFO  [STDOUT] [26 Mar 2012 12:34:56,040] DEBUG [SimpleUrlHandlerMapping] Mapping [/] to HandlerExecutionChain with handler [hello.web.controller.HelloWorldController@6159c4] and 2 interceptors
    12:34:56,046 INFO  [STDOUT] [26 Mar 2012 12:34:56,046] DEBUG [DispatcherServlet] Last-Modified value for [/hello-world-web/] is: -1
    12:34:56,073 INFO  [STDOUT] [26 Mar 2012 12:34:56,073] DEBUG [HandlerMethodInvoker] Invoking request handler method: public org.springframework.web.servlet.ModelAndView hello.web.controller.HelloWorldController.getHelloWorld(org.springframework.ui.ModelMap,javax.servlet.http.HttpServletRequest) throws javax.servlet.ServletException,java.io.IOException
    12:34:56,080 INFO  [STDOUT] [26 Mar 2012 12:34:56,080] DEBUG [DefaultListableBeanFactory] Invoking afterPropertiesSet() on bean with name 'HelloWorld'
    12:34:56,080 INFO  [STDOUT] [26 Mar 2012 12:34:56,080] DEBUG [DispatcherServlet] Rendering view [org.springframework.web.servlet.view.JstlView: name 'HelloWorld'; URL [/jsp/HelloWorld.jsp]] in DispatcherServlet with name 'hello-world'
    12:34:56,080 INFO  [STDOUT] [26 Mar 2012 12:34:56,080] DEBUG [JstlView] Added model object 'message' of type [java.lang.String] to request in view with name 'HelloWorld'
    12:34:56,100 INFO  [STDOUT] [26 Mar 2012 12:34:56,100] DEBUG [JstlView] Forwarding to resource [/jsp/HelloWorld.jsp] in InternalResourceView 'HelloWorld'
    12:34:56,370 INFO  [STDOUT] [26 Mar 2012 12:34:56,369] DEBUG [DispatcherServlet] Successfully completed request
    3.1.1.RELEASE DEBUG

    Code:
    12:36:00,004 INFO  [FsaEarDeployer] Started J2EE application: file:/C:/softwaredistribution/jboss-4.2.3.GA/server/hello-world/deploy/hello-world-ear-1.0.ear
    12:43:04,278 INFO  [STDOUT] [26 Mar 2012 12:43:04,278] DEBUG [DispatcherServlet] DispatcherServlet with name 'hello-world' processing GET request for [/hello-world-web/]
    12:43:04,281 INFO  [STDOUT] [26 Mar 2012 12:43:04,281] DEBUG [RequestMappingHandlerMapping] Looking up handler method for path /
    12:43:04,283 INFO  [STDOUT] [26 Mar 2012 12:43:04,283] DEBUG [RequestMappingHandlerMapping] Did not find handler method for [/]
    12:43:04,284 INFO  [STDOUT] [26 Mar 2012 12:43:04,284] DEBUG [SimpleUrlHandlerMapping] Mapping [/] to HandlerExecutionChain with handler [hello.web.controller.HelloWorldController@ccadbd] and 1 interceptor
    12:43:04,287 INFO  [STDOUT] [26 Mar 2012 12:43:04,287] DEBUG [ResponseStatusExceptionResolver] Resolving exception from handler [hello.web.controller.HelloWorldController@ccadbd]: javax.servlet.ServletException: No adapter for handler [hello.web.controller.HelloWorldController@ccadbd]: Does your handler implement a supported interface like Controller?
    12:43:04,287 INFO  [STDOUT] [26 Mar 2012 12:43:04,287] DEBUG [DefaultHandlerExceptionResolver] Resolving exception from handler [hello.web.controller.HelloWorldController@ccadbd]: javax.servlet.ServletException: No adapter for handler [hello.web.controller.HelloWorldController@ccadbd]: Does your handler implement a supported interface like Controller?
    12:43:04,289 INFO  [STDOUT] [26 Mar 2012 12:43:04,288] DEBUG [DispatcherServlet] Could not complete request
    javax.servlet.ServletException: No adapter for handler [hello.web.controller.HelloWorldController@ccadbd]: Does your handler implement a supported interface like Controller?
    Last edited by sparasker; Mar 26th, 2012, 03:16 PM. Reason: Removing properietary data

  • #2
    With 3.1 it isn't possible to mix @Controller with a Controller based UrlHandlerMapping as explained in the reference guide.

    Although you can make it work. However that would require you to remove mvc:annotation-driven and manually configure all the beans and instead of the RequestMappingHandlerAdapter/RequestMappingHandlerMapping use the older DefaultAnnotationHandlerMapping/AnnotationMethodHandlerAdapter.

    Comment


    • #3
      Thank you Marten for pointing me to the documentation. I don't know why I assumed it should automatically work.

      Here is what i did to fix the issue:

      Updated class level mapping for HelloWorldController
      Code:
      import java.io.IOException;
      
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServletRequest;
      
      import org.springframework.stereotype.Controller;
      import org.springframework.ui.ModelMap;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.bind.annotation.RequestMethod;
      import org.springframework.web.servlet.ModelAndView;
      
      @Controller
      @RequestMapping({"/", "/hello"})
      public class HelloWorldController {
      	
      	@RequestMapping(method = { RequestMethod.GET })
      	public ModelAndView getHelloWorld(ModelMap modelMap, HttpServletRequest req)
      			throws ServletException, IOException {
      
      		String aMessage = "Hello World MVC!";
      
      		ModelAndView modelAndView = new ModelAndView("HelloWorld");
      		modelAndView.addObject("message", aMessage);
      
      		return modelAndView;
      	}
      }
      Removed SimpleUrlHandlerMapping from hello-world-servlet.xml
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
      	xsi:schemaLocation="http://www.springframework.org/schema/beans
      		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      		http://www.springframework.org/schema/context
      		http://www.springframework.org/schema/context/spring-context-3.0.xsd
      		http://www.springframework.org/schema/mvc
      		http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
      
      	<!--
      		Register Annotation-based Post Processing Beans and @Components and
      		@Controller to deploy as beans
      	-->
      	<!--
      		Don't include packages that would pick up beans from the parent
      		application context the beans from the application-context will be
      		available here. Don't instantiate them again
      	-->
      	<context:component-scan base-package="hello.web.controller" />
      
      	<!-- Configures the @Controller programming model -->
      	<mvc:annotation-driven />
      
      	<bean id="viewResolver"
      		class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      		<property name="viewClass"
      			value="org.springframework.web.servlet.view.JstlView" />
      		<property name="prefix" value="/jsp/" />
      		<property name="suffix" value=".jsp" />
      	</bean>
      
      </beans>
      Now both the root ("/") and ("/hello") serve up HelloWorld.jsp

      Comment


      • #4
        I don't know why I assumed it should automatically work.
        In general that is a good assumption with newer versions of the spring framework in general in 99% of the cases this is true. But even in spring sometimes there is a breaking change and but in general these are documented in the reference guide.

        Comment

        Working...
        X