SpringBoot中獲取配置檔案中的屬性

2021-10-01 20:20:21 字數 960 閱讀 8117

配置檔案格式

# 設定正確的伺服器端口,8080埠可能已經被占用,可以使用其他的埠號

key-store-password: 123456

①簡單注入

@component

@configurationproperties(prefix = "spring.datasource")

public class server

②複雜注入

@component

@configurationproperties(prefix = "server")

public class server ';

} public int getport()

public void setport(int port)

public ssl getssl()

public void setssl(ssl ssl)

}//這裡不需要再次新增註解

public class ssl ';

}public string getkeystore()

public void setkeystore(string keystore)

public string getkey_alias()

public void setkey_alias(string key_alias)

public string getkey_store_password()

public void setkey_store_password(string key_store_password)

}

springboot 幾種屬性配置獲取

整個專案結構 1.通過 environment 去獲取屬性配置值 2.通過類註解 component 獲取類物件,再通過物件獲取屬性值,通過 value 給對應屬性賦值或者新增預設值 3.通過註解 component configurationproperties prefix gerry.prop...

springboot 幾種屬性配置獲取

整個專案結構 1.通過 environment 去獲取屬性配置值 2.通過類註解 component 獲取類物件,再通過物件獲取屬性值,通過 value 給對應屬性賦值或者新增預設值 3.通過註解 component configurationproperties prefix gerry.prop...

Spring Boot 獲取yaml配置檔案資訊

spring boot 專案啟動過程中 當程式步入listeners.environmentprepared environment 這裡後,就會讀取配置檔案中資訊。這句 不好除錯listeners.environmentprepared environment 在斷點處打上斷點,就可以看到系統是如...