组件扫描

(1)spa

<context:annotation-config />只在同一应用程序上下文中查找bean的注释。  这意味着,若是在DispatcherServlet的WebApplicationContext中放置<context:annotation-config />,那么它只会检查控制器中的@Autowired bean,而不是您的服务。有关详细信息,请参见第22.2节“DispatcherServlet”。 component

(2)   原型

使用<context:component-scan>隐式启用<context:annotation-config>的功能。        it

    使用<context:component-scan>时一般不须要包含<context:annotation-config>元素io

(3)程序

Spring提供了进一步的原型注释:@Component,@Service和@Controlle。@Component是任何Spring管理的组件的通用构造型。@Repository,@Service和@Controller是@Component的特殊化。异常

    若是您在服务层使用@Component或@Service之间进行选择,@Service显然是更好的选择。相似地,如上所述,@Repository已被支持做为持久层中自动异常转换的标记。@Controlle则是控制层的标记。注释

相关文章
相关标签/搜索