2013-08-05 68 views
1

通過閱讀本文,Spring 3 and JSR-330 @Inject and @Named example,建議在Spring 3之後使用JSR-330的標準註釋。因此,應該使用@Named而不是@Component,@Repository和@Service。但是如何在Spring MVC中使用@Controller?我意識到@Controller也是一個@Component,並且在使用@Named時我在測試中得到了相同的結果。但我想確定我是否缺少任何東西。Spring 3和JSR-330註釋

回答

0

Spring可以使用包掃描將控制器分別連接到其他組件。

例如,可能會在webmvc-config.xml中使用:

<context:component-scan base-package="com.xxx.yyy" use-default-filters="false"> 
    <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/> 
</context:component-scan> 

所以只需要檢查,如果在你的項目中存在任何這樣的事情。

+1

謝謝你的迴應。但我的問題是,由於JSR-330,我們應該使用'@Named公共類MyDao',而不是'@Repository public class MyDao'。我想知道我們是否也應該將相同的規則應用於控制器類。 –