spring项目启动执行特定方法

1. 方法上加注解@PostConstruct
@Compant
public class InitDemo{

@PostConstruct
public void init(){
//项目启动就会执行这个方法
doSomething();
}
}
2.xml配置init-method
<bean id="InitDemo" class="com.xxx.InitDemo" scope="singleton" init-method="init">
</bean>
3.实现InitializingBean接口,重写afterPropertiesSet方法
@Component
public class InitDemo implements InitializingBean {

@Override
public void afterPropertiesSet() throws Exception {

//doSomeThing
}

原文:https://blog.csdn.net/u010742049/article/details/82686059 

posted @ 2019-06-21 15:40  红尘524  阅读(1670)  评论(0编辑  收藏  举报