2013-08-05 66 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'。我想知道我们是否也应该将相同的规则应用于控制器类。 –