一、概念
概念和之前一样,这里介绍如何使用注解配置。更简单。
二、单例多例
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) //单例
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) //多例
三、懒加载
@Lazy
四、初始化和销毁方法
五、@Controller @Service @Repository @Component
这四个注解的功能是完全相同的,都是用来修饰类,将类声明为Spring管理的bean的。
其中@Component一般认为是通用的注解
而@Controller用在软件分层中的控制层,一般用在web层
而@Service用在软件分层中的业务访问层,一般用在service层
而@Repository用在软件分层中的数据访问层,一般用在dao层
完整代码下载
https://github.com/hailindai/SpringSample