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 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM