SpringBoot中對多個配置檔案中的屬性進行提取的簡易方法
阿新 • • 發佈:2018-11-27
我們要提取一下屬性:
首先建立一個GirlProperties類
package com.springboot.properties; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * @BelongsProject: springbootideademo * @BelongsPackage: com.springboot.properties * @Author: HUANG * @CreateTime: 2018-11-15 21:46 * @PROJECT_NAME: springbootideademo */ @Component @ConfigurationProperties(prefix = "girl") public class GirlProperties { private String cupSize; private Integer age; public String getCupSize() { return cupSize; } public void setCupSize(String cupSize) { this.cupSize = cupSize; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } }
呼叫方式:
通過屬性呼叫: