Spring MVC - mapping controller to urls using annotations

I am having problems setting up my Spring controller to map to specific URLs, and I have this up to a fairly simple script that I think should work:

I am setting up my controller class using annotations and it looks like this:

@Controller
@RequestMapping(value = "/question/**")
public class QuestionController 
{

    /**
     * Method to build users questions list
     * 
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("/list")
    public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //Display Questions List
    }
}

There is no additional configuration for the Controller, I just have the configuration <mvc:annotation-driven/>and the configuration <context:component-scan>..in my webmvc configuration, so the controller is automatically detected.

Now, when I go to /question/list, the applications cannot find the resource, and I get an error ResourceNotFound. However, if I go to /question/question/list, then the application will load the page that I would expect correctly.

, /question/question/list?


webmvc, RequestMappings alwaysUseFullPath = true, :

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" p:order="3">
        <property name="alwaysUseFullPath" value="true" />
    </bean>

, /question/list, , , Spring , ( URL-):

2011-08-09 18:02:27,885 [http-8080-3] DEBUG org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Matching patterns for request [/question/list] are [/question/**/list/, /question/**/list, /question/**/, /question/**]
2011-08-09 18:02:27,886 [http-8080-3] DEBUG org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapping [/question/list] to handler 'com.tmm.enterprise.microblog.controller.QuestionController@143c423'
2011-08-09 18:02:27,886 [http-8080-3] DEBUG org.springframework.web.servlet.DispatcherServlet - Last-Modified value for [/microblog/question/list] is: -1
2011-08-09 18:02:27,886 [http-8080-3] DEBUG org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'microblog' processing GET request for [/microblog/question/list]
2011-08-09 18:02:27,886 [http-8080-3] DEBUG org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Resolving exception from handler [com.tmm.enterprise.microblog.controller.QuestionController@143c423]: org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException: No matching handler method found for servlet request: path '/list', method 'GET', parameters map[[empty]]
2011-08-09 18:02:27,886 [http-8080-3] DEBUG org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Resolving to view 'resourceNotFound' for exception of type [org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException], based on exception mapping [.NoSuchRequestHandlingMethodException]
2011-08-09 18:02:27,887 [http-8080-3] DEBUG org.springframework.web.servlet.handler.SimpleMappingExceptionResolver - Exposing Exception as model attribute 'exception'

, , URL- , - - - ?


UPDATE

.

web.xml :

<servlet-mapping>
        <servlet-name>microblog</servlet-name>
        <url-pattern>/question/*</url-pattern>
    </servlet-mapping>

( -, .html ) URL-, , /question/list.html, ( @RequestMapping list() /list.html).

:

  • /question -

  • /question QuestionController

  • /list

, URL- .html - - , ? , , , - /question URL- (, /question/list , /question/question/list )

+5
3

set

<url-pattern>/</url-pattern> 

URL- html

<mvc:resources mapping="/resources/**" location="/resources/" />

, .css,.jpg ..

+4

/** .

@RequestMapping(value = "/question") .

/list /question.

/**, , , , -, /list .

, .

+2

, Rest API, : "org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException: ....."

, "Accept: application/json" " ". , .

0

All Articles