Spring DispatcherServlet: No mapping found for HTTP request

匿名 (未验证) 提交于 2019-12-03 01:48:02

问题:

I have an issue implementing a very simple page using spring mvc 3.2.4.RELEASE.

My controller looks like this:

@Transactional @Controller public class MembersDetailsController {     @Autowired     private MemberService memberService;      @RequestMapping(value = "/member/{name}", method = RequestMethod.GET)     public String displayMember(@PathVariable String name) {         System.out.println(name);         return "member";     }      @RequestMapping(value = "/member", method = RequestMethod.GET)     public String displayMember() {         System.out.println("Empty");         return "member";     } } 

When I call

http://127.0.0.1:8080/member 

the respective method is being executed as desired. However, wenn I call

http://127.0.0.1:8080/member/test 

or

http://127.0.0.1:8080/member/test/ 

I get a 404 with the log-output:

WARN  org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/member/test] in DispatcherServlet with name 'mvc-dispatcher' 

Whats really weired is the a previous log says:

INFO  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/member/{name}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String  INFO  org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/member],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String 

Which means that the mapping should be correct as far as I understand this.

This is my web.xml:

MitgliederdatenbankcontextConfigLocation/WEB-INF/spring-security.xml, /WEB-INF/applicationContext.xmlhibernateFilterorg.springframework.orm.hibernate3.support.OpenSessionInViewFiltersessionFactoryBeanNamehibernateSessionFactoryspringSecurityFilterChainorg.springframework.web.filter.DelegatingFilterProxyhibernateFilter/*springSecurityFilterChain/*org.springframework.web.context.ContextLoaderListenerspringGwtRemoteServiceServletorg.spring4gwt.server.SpringGwtRemoteServiceServletmvc-dispatcherorg.springframework.web.servlet.DispatcherServletcontextConfigLocation/WEB-INF/applicationContext.xml1springGwtRemoteServiceServlet/ui/springGwtServices/*mvc-dispatcher/welcomemvc-dispatcher/loginmvc-dispatcher/logoutmvc-dispatcher/loginfailedmvc-dispatcher/member/*/login

Could anybody please give me a hint what went wrong here?

回答1:

I believe that the problem is the same one as described here URL Mapping issue - Spring web MVC .

Unless you use alwaysUseFullPath spring mvc will match * part to the mapping you specified (e.g. /member/member/test ). See docs for alwaysUseFullPath here (section 17.4) http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html .

However, unfortunately, this property is not exposed through xml configuration element (if you're using xml configuration) so if you'd like your mappings to work the way you discribed in your question you'll need to configure it as described here: http://blog.sarathonline.com/2013/07/enable-alwaysusefullpath-with.html



回答2:

I was faced with the same problem and solved problem by using

This tag will configure two beans DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter.

Also I added tag to my dispatcher servlet config file.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!