一、概念
? ? ? ? 概念和之前一樣,這里介紹如何使用注解配置。更簡單。
二、單例多例
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) //單例
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) //多例
三、懶加載
@Lazy
四、初始化和銷毀方法

五、@Controller @Service @Repository @Component
這四個(gè)注解的功能是完全相同的,都是用來修飾類,將類聲明為Spring管理的bean的。
其中@Component一般認(rèn)為是通用的注解
而@Controller用在軟件分層中的控制層,一般用在web層
而@Service用在軟件分層中的業(yè)務(wù)訪問層,一般用在service層
而@Repository用在軟件分層中的數(shù)據(jù)訪問層,一般用在dao層
完整代碼下載
????????https://github.com/hailindai/SpringSample