@PostConstruct注解注释的方法
@Compant public class InitDemo{ @PostConstruct public void init(){ //项目启动就会执行这个方法 doSomething(); } }
xml中配置如下方式
<bean id="InitDemo" class="com.xxx.InitDemo" scope="singleton" init-method="init"> </bean>
或者实现InitiallizingBean,在arterPropertiesSet方法中
@Component public class InitDemo implements InitializingBean { @Override public void afterPropertiesSet() throws Exception { //doSomeThing } 参考:https://blog.csdn.net/u010742049/article/details/82686059
执行顺序。 构造函数 > @PostConstruct > InitiallizingBean > init-method