Spring MVC Mapping问题

我有我认为是一个简单的Spring MVC应用程序。 但是,我似乎可以正确设置requestMappings。 奇怪的是,日志显示url被映射到适当的控制器,但Dispatcher似乎无法在运行时找到它。 我们欢迎所有的建议:

日志

INFO: Mapped URL path [/app/index] onto handler [com.noisyair.whatisayis.web.MainController@420a52f] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/app/index.*] onto handler [com.noisyair.whatisayis.web.MainController@420a52f] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/app/index/] onto handler [com.noisyair.whatisayis.web.MainController@420a52f] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/app/tags/{tag}] onto handler [com.noisyair.whatisayis.web.SearchByTagController@7b3cb2c6] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/app/tags/{tag}.*] onto handler [com.noisyair.whatisayis.web.SearchByTagController@7b3cb2c6] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler INFO: Mapped URL path [/app/tags/{tag}/] onto handler [com.noisyair.whatisayis.web.SearchByTagController@7b3cb2c6] Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.FrameworkServlet initServletBean INFO: FrameworkServlet 'wisi': initialization completed in 237 ms Jan 11, 2010 2:14:21 PM org.apache.catalina.core.StandardContext start INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/] has already been started Jan 11, 2010 2:14:41 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping found for HTTP request with URI [/app/index] in DispatcherServlet with name 'wisi' 

Web.xml文件

  org.springframework.web.context.ContextLoaderListener    wisi org.springframework.web.servlet.DispatcherServlet  1   wisi /app/*  

控制器类:

 @Controller public class MainController { @Autowired private LearningEntryService learningEntryService; public LearningEntryService getLearningEntryService() { return learningEntryService; } public void setLearningEntryService(LearningEntryService learningEntryService) { this.learningEntryService = learningEntryService; } @RequestMapping(value = "/app/index", method = RequestMethod.GET) public ModelAndView sayHello(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Map model = new HashMap(); List le = learningEntryService.getLearningEntries(); model.put("learningEntries", le); return new ModelAndView("main", model); } } 

你不应该在@RequestMapping复制“/ app”。 也就是说,你的sayHello现在被映射到“/ app / app / index”。 你可以写

 @RequestMapping(value = "/index", method = RequestMethod.GET) 

(或者您可以在配置中声明DefaultAnnotationHandlerMapping bean并将其allwaysUseFullPath属性设置为true以覆盖默认行为)