2010-01-11 70 views
4

我有我认为是一个简单的Spring MVC应用程序。不过,我似乎可以正确设置requestMappings。奇怪的是,日志显示url映射到正确的控制器,但Dispatcher似乎无法在运行时找到它。任何建议,将不胜感激:春天的MVC映射问题

登录

INFO: Mapped URL path [/app/index] onto handler  [[email protected]] 
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/app/index.*] onto handler [[email protected]] 
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/app/index/] onto handler [[email protected]] 
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/app/tags/{tag}] onto handler [[email protected]] 
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/app/tags/{tag}.*] onto handler [[email protected]] 
Jan 11, 2010 2:14:21 PM org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler 
INFO: Mapped URL path [/app/tags/{tag}/] onto handler [[email protected]] 
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文件

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- The Spring MVC framework handles all of this stuff. Just pass it along --> 
<servlet> 
    <servlet-name>wisi</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>wisi</servlet-name> 
    <url-pattern>/app/*</url-pattern> 
</servlet-mapping> 

控制器类:

@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<String, Object> model = new HashMap<String, Object>(); 
    List<LearningEntry> le = learningEntryService.getLearningEntries(); 
    model.put("learningEntries", le); 
    return new ModelAndView("main", model); 
} 
} 

回答

16

您不能重复在 “/应用程序” @RequestMapping<url-pattern>。也就是说,你的sayHello现在被映射到“/ app/app/index”。你可以写

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

(或者你可以在你的配置声明DefaultAnnotationHandlerMapping豆及其allwaysUseFullPath属性设置为true覆盖默认行为)

+1

+1好对象,我没有当场表示 – skaffman 2010-01-11 22:32:37

+0

完美,这修好了,谢谢 – 2010-01-11 23:21:04