# spring-boot-demo-properties
> 本 demo 演示如何获取配置文件的自定义配置,以及如何多环境下的配置文件信息的获取
## pom.xml
```xml
* 项目配置 *
* * @author yangkai.shen * @date Created in 2018-09-29 10:50 */ @Data @Component public class ApplicationProperty { @Value("${application.name}") private String name; @Value("${application.version}") private String version; } ``` ## DeveloperProperty.java ```java /** ** 开发人员配置信息 *
* * @author yangkai.shen * @date Created in 2018-09-29 10:51 */ @Data @ConfigurationProperties(prefix = "developer") @Component public class DeveloperProperty { private String name; private String website; private String qq; private String phoneNumber; } ``` ## PropertyController.java ```java /** ** 测试Controller *
* * @author yangkai.shen * @date Created in 2018-09-29 10:49 */ @RestController public class PropertyController { private final ApplicationProperty applicationProperty; private final DeveloperProperty developerProperty; @Autowired public PropertyController(ApplicationProperty applicationProperty, DeveloperProperty developerProperty) { this.applicationProperty = applicationProperty; this.developerProperty = developerProperty; } @GetMapping("/property") public Dict index() { return Dict.create().set("applicationProperty", applicationProperty).set("developerProperty", developerProperty); } } ``` ## additional-spring-configuration-metadata.json > 位置: src/main/resources/META-INF/additional-spring-configuration-metadata.json ```json { "properties": [ { "name": "application.name", "description": "Default value is artifactId in pom.xml.", "type": "java.lang.String" }, { "name": "application.version", "description": "Default value is version in pom.xml.", "type": "java.lang.String" }, { "name": "developer.name", "description": "The Developer Name.", "type": "java.lang.String" }, { "name": "developer.website", "description": "The Developer Website.", "type": "java.lang.String" }, { "name": "developer.qq", "description": "The Developer QQ Number.", "type": "java.lang.String" }, { "name": "developer.phone-number", "description": "The Developer Phone Number.", "type": "java.lang.String" } ] } ```