2011-07-07 66 views
0

我正在使用Spring 3.0.5。我的注释控制器都没有被识别。我有我的应用程序的XML ...无法映射到工作

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://www.springframework.org/schema/beans" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.0.xsd"> 

<mvc:resources mapping="/static/**" location="/static/"/> 
<mvc:annotation-driven/> 
<context:component-scan base-package="com.myco.systems.leadsmonitor"/> 

我的静态资产正在拾起罚款。但我发现了一个404,当我试图达成一个注解控制器...

package com.myco.systems.leadsmonitor.web.controller; 

@Controller 
public class HomeController { 

    … 

    @RequestMapping("/") 
    public void index(Model model) { 
     model.addAttribute("latestLeadTime", MonitorStatistics.getInstance().getLatestLeadCreationTime()); 
     model.addAttribute("lastDBCheck", MonitorStatistics.getInstance().getLastDBCheck()); 
    } 

些什么,我需要做的就是我的控制器由Spring回升?谢谢, - 戴夫

+0

什么是在web.xml中用于Spring DispatcherServlet的URL模式? –

回答

0

我认为你得到404的原因是因为该视图没有在控制器方法中解决。默认情况下,一个void返回类型会根据URI映射到一个视图名称,在你的情况下,由于路径是“/”,它可能会被解析为“”,它不会映射到任何逻辑视图。

你可以尝试两件事情:

  1. 开始在调试模式,看看你的要求实际上是来到RequestMapping方法
  2. 如果是,你能明确地返回从视图名称你的方法,看看这个视图名称是否得到解析到一个正确的视图(假设你有一个视图解析器注册)
0

你应该检查web.xml中的URL映射和查看您的弹簧配置中的分辨率配置。

一个很好的资源是春天的Example.org

见:http://www.springbyexample.org/examples/simple-spring-mvc-form-annotation-config-webapp.html

另外一个是SpringSource的工具套件(STS),在那里他们引导您完成创建Spring MVC Web应用程序提供的教程。这些教程通常包含来自tuckey.org的UrlRewriteFilter。

例如, servlet映射到/ app,然后添加此servlet过滤器

<!-- Enables clean URLs with JSP views e.g. /welcome instead of /app/welcome --> 
<filter> 
    <filter-name>UrlRewriteFilter</filter-name> 
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> 
<!--  <init-param>--> 
<!--   <param-name>logLevel</param-name>--> 
<!--   <param-value>DEBUG</param-value>--> 
<!--  </init-param>--> 

</filter>