【Spring】12:注解开发中,bean作用范围和生命周期

158 阅读1分钟

@Scope:设置bean的作用范围

@PostConstruct:设置bean的初始化方法

@PreDestroy:设置bean的销毁方法

@Repository
@Scope("singleton")
public class BookDaoImpl implements BookDao {

    public void save() {
        System.out.println("book dao save ...");
    }
    @PostConstruct
    public void init() {
        System.out.println("init ...");
    }
    @PreDestroy
    public void destroy() {
        System.out.println("destroy ...");
    }

}