1. 程式人生 > >spring-boot配置文件使用

spring-boot配置文件使用

one rop boot 生產 參數 註解註入 環境 開發環境 ring

配置文件格式兩種application.properties和application.yml

.yml配置的使用

1、使用@Value("${配置文件中的屬性名}")註解註入配置內容

2、在配置中引用配置

  ${配置文件中的屬性名}

3、配置註入到實體類註解@ConfigurationProperties(prefix = "girl")

  同時為了自動裝配,需要@Component

4、多環境配置

  開發環境和生產環境配置切換 spring: profiles: active: xxx

  啟動時加配置文件參數 jave -jar .... --spring.profile.active=xxxx

spring-boot配置文件使用