URL Mapping issue - Spring web MVC

前端 未结 3 961
我寻月下人不归
我寻月下人不归 2020-12-06 01:17

I\'m a newbie with Spring and web MVC module. Basically, i have the following :

web.xml


    abc-dispatcher

        
相关标签:
3条回答
  • 2020-12-06 01:45

    The URL should be http://localhost:8080/myapp/user/user/welcome. Indeed, unless the alwaysUseFullPath property of the handler is set to true, the servlet-mapping is prepended to the request mapping URL to form the full path.

    See http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#mvc-handlermapping for details:

    alwaysUseFullPath

    If true , Spring uses the full path within the current Servlet context to find an appropriate handler. If false (the default), the path within the current Servlet mapping is used. For example, if a Servlet is mapped using /testing/* and the alwaysUseFullPath property is set to true, /testing/viewPage.html is used, whereas if the property is set to false, /viewPage.html is used.

    0 讨论(0)
  • 2020-12-06 01:48

    For me, the problem was that I was using the deprecated DefaultAnnotationHandlerMapping, and even if setting the alwaysUseFullPath to true, it didn't take effect, however replacing DefaultAnnotationHandlerMapping in benefit of RequestMappingHandlerMapping with the alwaysUseFullPath set to true solved the problem.

    <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
        <property name="alwaysUseFullPath" value="true"></property>
    </bean>
    
    0 讨论(0)
  • 2020-12-06 01:54

    It's' been added context:component-scan element into the sample context file snippet but there is no <annotation-driven/> element that says spring framework to look for controllers annotated with @Controller

    0 讨论(0)
提交回复
热议问题