首页 > 移动平台 > 详细

@postConstruct constructor afterSetProperties() setApplicationContext 执行顺序

时间:2020-01-20 20:01:47      阅读:402      评论:0      收藏:0      [点我收藏+]
测试代码:

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
@Component
public class LoadSequence implements InitializingBean, ApplicationContextAware {
@Value("${DISTRIBUTED_LOCK}")
private String code;


public LoadSequence(){
System.out.println("constructor has runned:" + code);
}
@PostConstruct
public void postConstruct(){
System.out.println("postConstruct has runned:" + code);
}

@Override
public void afterPropertiesSet() throws Exception {
System.out.println("afterPropertiesSet has runned:" + code);
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
System.out.println("setApplicationContext has runned:" + code);
}
}


结果:

constructor has runned:null
setApplicationContext has runned:false
postConstruct has runned:false
afterPropertiesSet has runned:false

@postConstruct constructor afterSetProperties() setApplicationContext 执行顺序

原文:https://www.cnblogs.com/kaoli/p/12213848.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!