SpringBoot小常识系列--配置文件相关属性的命名规则
SpringBoot 支持松散的属性名称匹配方式,所以配置文件中的名称可以是:
- Kebab case(小写+横线分隔),例如:
acme.my-project.person.first-name
- 标准的camel格式,例如:
acme.myProject.person.firstName
大写+下划线或小写+下划线格式,例如:ACME_MYPROJECT_PERSON_FIRSTNAME 或 acme.my_project.person.first_name
!!! 需要注意的是,在annotation下的prefix的值必须是Kebab case格式, 例如:ConfigurationProperties注解的prefix属性 !!!
@Component
@ConfigurationProperties(prefix = "app.test-prop", ignoreUnknownFields = true)
@Validated
@Getter
@Setter
public class TestProperties {
@NotBlank
private String abcdRecogInterface;
}