亚欧色一区w666天堂,色情一区二区三区免费看,少妇特黄A片一区二区三区,亚洲人成网站999久久久综合,国产av熟女一区二区三区

  • 發布文章
  • 消息中心
點贊
收藏
評論
分享
原創

SpringBean初始化順序

2023-12-13 06:31:55
9
0

Spring bean是(shi)Spring框架在運行時管理的(de)對象。Spring bean是(shi)任(ren)何(he)Spring應用(yong)程序的(de)基本構建塊。我(wo)們編寫的(de)大多數(shu)應用(yong)程序邏輯代碼都將放在Spring bean中。

執行(xing)順序:

Constructor > @Autowired > @PostConstruct > InitializingBean > init-method

因此(ci)不能(neng)在構造函(han)數中(zhong)直接使用@Autowired定義的參數(shu),而(er)應(ying)該在@PostConstruct中調用。

例(li)如:

public class Metric {
?
   @Autowired
   MonitorMetric monitorMetric;
?
   final String string;
?
   // 構造函數
   public Metric(String string){
       this.string = string;
  }
?
   // 在 PostConstruct 中獲(huo)取 Autowired 的(de)值
   @PostConstruct
   public String initialize(){
       return monitorMetric.getStr();
  }
}

 

 

 

0條評論
0 / 1000
代碼的路
100文章數
1粉絲數
代碼的路
100 文(wen)章 | 1 粉絲(si)
代碼的路
100文章(zhang)數
1粉絲數
代碼的路
100 文章 | 1 粉(fen)絲
原(yuan)創

SpringBean初始化順序

2023-12-13 06:31:55
9
0

Spring bean是Spring框架在運(yun)行時管(guan)理的對(dui)象。Spring bean是任何Spring應(ying)用(yong)程(cheng)序的基(ji)本構(gou)建塊。我們編寫的大多數(shu)應(ying)用(yong)程(cheng)序邏(luo)輯代碼都(dou)將放在Spring bean中(zhong)。

執行順序:

Constructor > @Autowired > @PostConstruct > InitializingBean > init-method

因此不能在構造函數中(zhong)直接使用@Autowired定義的參(can)數,而應該在@PostConstruct中調(diao)用。

例如:

public class Metric {
?
   @Autowired
   MonitorMetric monitorMetric;
?
   final String string;
?
   // 構造函數
   public Metric(String string){
       this.string = string;
  }
?
   // 在 PostConstruct 中獲(huo)取 Autowired 的值
   @PostConstruct
   public String initialize(){
       return monitorMetric.getStr();
  }
}

 

 

 

文章來自個人專欄
文章(zhang) | 訂(ding)閱
0條評論
0 / 1000
請輸入你的評論
0
0