项目启动之后进行一些初始化的方法

 

@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

posted on 2019-06-05 17:11  敲代马  阅读(183)  评论(0编辑  收藏  举报

导航