組件掃描

(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則是控制層的標記。註釋

相關文章
相關標籤/搜索