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