SpringBoot小常识系列--配置文件相关属性的命名规则

SpringBoot小常识系列--配置文件相关属性的命名规则

参见官方文档: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-relaxed-binding

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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章