2011-07-07 4 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()); 
    } 

他に何私は私のコントローラは春によってピックアップを取得するために何が必要ですか?ありがとう、 - Dave

+0

web.xmlのSpring DispatcherServletに使用するURLパターンは何ですか? –

答えて

0

私が404を取得している理由は、ビューがcontollerメソッドで解決されていないためです。デフォルトでは、パスが "/"であるためURIを基にしたビュー名を使用してvoid戻り値の型がマップされ、論理ビューにマップされない ""に解決される可能性があります。もしそうであれば、あなたの要求は、実際にRequestMapping方法

  • に来ている場合は、明示的からビュー名を返すことができ、デバッグモードで

    1. スタートし、次を参照してください。

      あなたは物事のカップルを試すことができます

  • 0

    web.xmlのURLマッピングとビューの解像度設定をスプリング設定で確認する必要があります。このビューの名前が正しいビューに解決されているかどうかを確認してください(ビューリゾルバが登録されていると仮定します)。

    一つの良いリソースは、スプリングによってExample.orgある

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

    もう一つは、彼らが春のMVC Webアプリケーションを作成する手順をSpringSourceのツールスイート(STS)、で利用できるチュートリアルです。これらのチュートリアルには、通常、tuckey.orgのUrlRewriteFilterが含まれています。

    サーブレットを/ appにマップしてからこのサーブレットフィルタを追加します

    <!-- 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> 
    
    関連する問題