标签属性 | 对应的注解 |
|---|---|
| id | @Component(value = "id"),设置bean对象的名称 |
| lazy-init | @Lazy,标注bean是否延迟加载,ture/false |
| scope | @Scope("scope"),标注bean的作用范围 |
init-method | @PostConstruct,在方法上使用,标注bean实例化后所执行的方法 |
destroy-method | @PreDestroy,在方法上使用,标注bean的销毁前zh |
- package com.example.DAO.Impl;
-
- import com.example.DAO.UserDAO;
- import org.springframework.context.annotation.Lazy;
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Component;
-
- import javax.annotation.PostConstruct;
- import javax.annotation.PreDestroy;
-
- @Component("userDAO")// 设置bean对象的名称
- @Scope("singleton")
- @Lazy(value = false)
-
- public class UserDAOImpl implements UserDAO {
- public UserDAOImpl() {
- System.out.println("userDAO创建......");
- }
-
- @PostConstruct
- public void init() {
- System.out.println("userDAo初始化方法");
- }
-
- @PreDestroy
- public void destroy() {
- System.out.println("userDAo销毁方法");
- }
- }