1.注解方式
在 bean 初始化时会经历几个阶段,首先可以使用注解 @PostConstruct
, @PreDestroy
来在 bean 的创建和销毁阶段进行调用:
@Component
public class AnnotationBean {
private final static Logger LOGGER = LoggerFactory.getLogger(AnnotationBean.class);
@PostConstruct
public void start(){
LOGGER.info("AnnotationBean start");
}
@PreDestroy
public