1. 方法上加注解@PostConstruct
@Compantpublic 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方法@Componentpublic class InitDemo implements InitializingBean {@Override
public void afterPropertiesSet() throws Exception {//doSomeThing
}原文:https://blog.csdn.net/u010742049/article/details/82686059