本文对应Spring Boot 2.2.6.RELEASE
版本。
Spring Boot配置元数据“metadata”
1.什么是配置元数据metedata?
在Spring Boot的jar包中包含了metadata文件,提供了所有支持的配置属性的详情(例如属性名称、类型等)。这些文件旨在让IDE在开发者使用application.properties
或者 application.yml
配置文件时提供上下文帮助和“自动代码完成”的功能。
大多数元数据文件是在编译时通过处理带有@ConfigurationProperties注释的所有项自动生成的。另外,开发者也可以为特殊或更高级的用法手动编写部分元数据。
2.配置元数据的格式
配置元数据文件位于jar包的 META-INF/spring-configuration-metadata.json
文件中,这些文件使用json
格式,如下所示:
{
"groups": [
{
"name": "server",
"type": "org.springframework.boot.autoconfigure.web.ServerProperties",
"sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
},
{
"name": "spring.jpa.hibernate",
"type": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate",
"sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties",
"sourceMethod": "getHibernate()"
}
...
],"properties": [
{
"name": "server.port",
"type": "java.lang.Integer",
"sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
},
{
"name": "server.address",
"type":