2009-08-28 18 views
1

注釈付きコントローラを使用しているスプリングコントローラは初めてです。ここで Spring AnnotationHandlerマッピングが動作しない

Bean定義私の構成です

<bean 
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 

コントローラ

指定されたURLの春にアクセスしようとした警告を投げている
package learn.web.controller.annotation; 

import javax.servlet.http.HttpServletRequest; 

import learn.web.controller.BaseController; 

import org.springframework.context.support.ReloadableResourceBundleMessageSource; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.servlet.ModelAndView; 

@Controller 
public class FirstController extends BaseController { 

    @RequestMapping("/annotation/first.ftl") 
    public ModelAndView first(HttpServletRequest request) { 

     if(messageSource instanceof ReloadableResourceBundleMessageSource){ 
      ReloadableResourceBundleMessageSource m = (ReloadableResourceBundleMessageSource) messageSource; 
      m.clearCache(); 
     } 

     messageSource.getMessage("learn.message.first", new Object[] {}, 
       localResolver.resolveLocale(request)); 

     return new ModelAndView("/annotation/first"); 
    } 

} 

org.springframework.web.servlet.PageNotFound - 名前が 'springapp'のDispatcherServletのURI [/Learn/annotation/first.ftl]を持つHTTPリクエストのマッピングが見つかりません

答えて

0

は、私は何が不足していることはコンポーネントスキャン

<context:component-scan base-package="learn.web.controller" /> 

ご使用の構成にこれを追加してみてくださいだと思います。

これは

あなたの設定は、この

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-2.5.xsd"> 

    <context:component-scan base-package="learn.web.controller" /> 
    <bean 
    class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 

</beans> 
のように見えるかもしれ指定されたパッケージからすべての注釈付きのコンポーネントをロードします
関連する問題