1. 加载方式
@ConfigurationProperties(prefix = "another")
@Bean
public AnotherComponent anotherComponent() { ... }
@ConfigurationProperties("acme")
public class AcmeProperties {}
2 .Binding Maps
When binding to Map properties, if the key contains anything other than lowercase alpha-numeric characters or -, you need to use the bracket notation so that the original value is preserved. If the key is not surrounded by [], any characters that are not alpha-numeric or - are removed. For example, consider binding the following properties to a Map:
@ConfigurationProperties("acme")
public class AcmeProperties {
private final Map<String, MyPojo> map = new HashMap<>();
public Map<String, MyPojo> getMap() {
return this.map;
}
}
3. List
4.注意事项
PORT binds to port
To convert a property name in the canonical-form to an environment variable name you can follow these rules:
• Replace dots (.) with underscores (_).
• Remove any dashes (-).
• Convert to uppercase
For example, the configuration property spring.main.log-startup-info would be an environment variable named SPRING_MAIN_LOGSTARTUPINFO.
@Value("{demo.item-price}") will pick up demo.item-price and demo.itemPrice forms from the application.properties file, as well as DEMO_ITEMPRICE from the system environment. If you used @Value("{demo.itemPrice}") instead, demo.item-price and DEMO_ITEMPRICE would not be considered.
5.实际应用
@Configuration
@ConfigurationProperties(prefix = "weixinapi")
@Data
public class WxProperties {
private String baseUrl;
private String secret;
private String appId;
private String grantType;
}
@Autowired
private WxProperties wxProperties;