spring项目启动执行特定方法
生活随笔
收集整理的這篇文章主要介紹了
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?
轉載于:https://www.cnblogs.com/helloworld-1024/p/11064956.html
總結
以上是生活随笔為你收集整理的spring项目启动执行特定方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: atomic原子类实现机制_并发编程:并
- 下一篇: 【各学校通用】5分钟刷完天津科技大学雨课