此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.4.3spring-doc.cadn.net.cn

元数据格式

配置元数据文件位于 jar 内的META-INF/spring-configuration-metadata.json. 它们使用 JSON 格式,其中项目分类在“groups”或“properties”下,附加值提示分类在“hints”下,忽略的项目分类在“ignored”下,如以下示例所示:spring-doc.cadn.net.cn

{"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": "java.net.InetAddress",
		"sourceType": "org.springframework.boot.autoconfigure.web.ServerProperties"
	},
	{
		  "name": "spring.jpa.hibernate.ddl-auto",
		  "type": "java.lang.String",
		  "description": "DDL mode. This is actually a shortcut for the \"hibernate.hbm2ddl.auto\" property.",
		  "sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate"
	}
	...
],"hints": [
	{
		"name": "spring.jpa.hibernate.ddl-auto",
		"values": [
			{
				"value": "none",
				"description": "Disable DDL handling."
			},
			{
				"value": "validate",
				"description": "Validate the schema, make no changes to the database."
			},
			{
				"value": "update",
				"description": "Update the schema if necessary."
			},
			{
				"value": "create",
				"description": "Create the schema and destroy previous data."
			},
			{
				"value": "create-drop",
				"description": "Create and then destroy the schema at the end of the session."
			}
		]
	}
	...
],"ignored": {
	"properties": [
		{
			"name": "server.ignored"
		}
		...
	]
}}

每个 “property” 都是用户使用给定值指定的配置项。 例如server.portserver.address可以在application.properties/application.yaml如下:spring-doc.cadn.net.cn

server.port=9090
server.address=127.0.0.1
server:
  port: 9090
  address: 127.0.0.1

“组”是更高级别的项目,它们本身不指定值,而是为属性提供上下文分组。 例如,server.portserver.address属性是server群。spring-doc.cadn.net.cn

不要求每个 “property” 都有一个 “group”。 某些属性可能本身就存在。

“提示”是用于帮助用户配置给定属性的附加信息。 例如,当开发人员配置spring.jpa.hibernate.ddl-auto属性中,工具可以使用提示为none,validate,update,createcreate-drop值。spring-doc.cadn.net.cn

最后,“ignored” 用于被故意忽略的项目。 此部分的内容通常来自其他元数据spring-doc.cadn.net.cn

组属性

包含在groups数组可以包含下表中显示的属性:spring-doc.cadn.net.cn

名字 类型 目的

namespring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

组的全名。 此属性是必需的。spring-doc.cadn.net.cn

typespring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

组数据类型的类名。 例如,如果组基于一个带有@ConfigurationProperties,则该属性将包含该类的完全限定名称。 如果它基于@Beanmethod,它将是该方法的返回类型。 如果类型未知,则可以省略该属性。spring-doc.cadn.net.cn

descriptionspring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

可向用户显示的组的简短描述。 如果没有可用的描述,则可以省略它。 建议描述为简短的段落,第一行提供简明的摘要。 描述中的最后一行应以句点 (.).spring-doc.cadn.net.cn

sourceTypespring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

提供此组的源的类名。 例如,如果组基于@Bean方法注释@ConfigurationProperties,则此属性将包含@Configuration类。 如果源类型未知,则可以省略该属性。spring-doc.cadn.net.cn

sourceMethodspring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

提供此组的方法的全名(包括括号和参数类型)(例如,一个@ConfigurationProperties注释@Bean方法)。 如果源方法未知,则可以省略它。spring-doc.cadn.net.cn

属性属性

包含在properties数组可以包含下表中描述的属性:spring-doc.cadn.net.cn

名字 类型 目的

namespring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

属性的全名。 名称采用小写句点分隔形式(例如server.address). 此属性是必需的。spring-doc.cadn.net.cn

typespring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

属性数据类型的完整签名(例如String),但也是一个完整的泛型类型(例如java.util.Map<java.lang.String,com.example.MyEnum>). 您可以使用此属性来指导用户了解他们可以输入的值类型。 为了保持一致性,原语的类型通过使用其包装器对应项(例如boolean成为Boolean). 请注意,此类可能是从String作为值绑定。 如果类型未知,则可以省略。spring-doc.cadn.net.cn

descriptionspring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

可向用户显示的属性的简短说明。 如果没有可用的描述,则可以省略它。 建议描述为简短的段落,第一行提供简明的摘要。 描述中的最后一行应以句点 (.).spring-doc.cadn.net.cn

sourceTypespring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

提供此属性的源的类名。 例如,如果属性来自一个带有@ConfigurationProperties,此属性将包含该类的完全限定名称。 如果源类型未知,则可以省略它。spring-doc.cadn.net.cn

defaultValuespring-doc.cadn.net.cn

对象spring-doc.cadn.net.cn

默认值,如果未指定属性,则使用该值。 如果属性的类型是数组,它可以是值的数组。 如果默认值未知,则可以省略它。spring-doc.cadn.net.cn

deprecationspring-doc.cadn.net.cn

折旧spring-doc.cadn.net.cn

指定是否弃用该属性。 如果该字段未弃用或该信息未知,则可以省略该字段。 下表提供了有关deprecation属性。spring-doc.cadn.net.cn

包含在deprecation每个properties元素可以包含以下属性:spring-doc.cadn.net.cn

名字 类型 目的

levelspring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

弃用级别,可以是warning(默认)或error. 当属性具有warningdeprecation 级别,它仍应在环境中绑定。 但是,当它具有errordeprecation 级别,则该属性不再被管理且未绑定。spring-doc.cadn.net.cn

reasonspring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

弃用属性的原因的简短描述。 如果没有可用的原因,则可以省略。 建议描述为简短的段落,第一行提供简明的摘要。 描述中的最后一行应以句点 (.).spring-doc.cadn.net.cn

replacementspring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

替换此已弃用属性的属性的全名。 如果此属性没有替代项,则可以省略它。spring-doc.cadn.net.cn

sincespring-doc.cadn.net.cn

字符串spring-doc.cadn.net.cn

属性已弃用的版本。 可以省略。spring-doc.cadn.net.cn

在 Spring Boot 1.3 之前,单个deprecatedboolean 属性代替deprecation元素。 这仍然以已弃用的方式受支持,不应再使用。 如果没有可用的原因和替换项,则为空的deprecationobject 的

弃用也可以在代码中以声明方式指定,方法是将@DeprecatedConfigurationProperty注解传递给 getter 来公开已弃用的属性。 例如,假设my.app.targetproperty 令人困惑,并被重命名为my.app.name. 以下示例显示如何处理这种情况:spring-doc.cadn.net.cn

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;

@ConfigurationProperties("my.app")
public class MyProperties {

	private String name;

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Deprecated
	@DeprecatedConfigurationProperty(replacement = "my.app.name")
	public String getTarget() {
		return this.name;
	}

	@Deprecated
	public void setTarget(String target) {
		this.name = target;
	}

}
There is no way to set a level. warning is always assumed, since code is still handling the property.

The preceding code makes sure that the deprecated property still works (delegating to the name property behind the scenes). Once the getTarget and setTarget methods can be removed from your public API, the automatic deprecation hint in the metadata goes away as well. If you want to keep a hint, adding manual metadata with an error deprecation level ensures that users are still informed about that property. Doing so is particularly useful when a replacement is provided.spring-doc.cadn.net.cn

Hint Attributes

The JSON object contained in the hints array can contain the attributes shown in the following table:spring-doc.cadn.net.cn

Name Type Purpose

namespring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

The full name of the property to which this hint refers. Names are in lower-case period-separated form (such as spring.mvc.servlet.path). If the property refers to a map (such as system.contexts), the hint either applies to the keys of the map (system.contexts.keys) or the values (system.contexts.values) of the map. This attribute is mandatory.spring-doc.cadn.net.cn

valuesspring-doc.cadn.net.cn

ValueHint[]spring-doc.cadn.net.cn

A list of valid values as defined by the ValueHint object (described in the next table). Each entry defines the value and may have a description.spring-doc.cadn.net.cn

providersspring-doc.cadn.net.cn

ValueProvider[]spring-doc.cadn.net.cn

A list of providers as defined by the ValueProvider object (described later in this document). Each entry defines the name of the provider and its parameters, if any.spring-doc.cadn.net.cn

The JSON object contained in the values attribute of each hint element can contain the attributes described in the following table:spring-doc.cadn.net.cn

Name Type Purpose

valuespring-doc.cadn.net.cn

Objectspring-doc.cadn.net.cn

A valid value for the element to which the hint refers. If the type of the property is an array, it can also be an array of value(s). This attribute is mandatory.spring-doc.cadn.net.cn

descriptionspring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

A short description of the value that can be displayed to users. If no description is available, it may be omitted. It is recommended that descriptions be short paragraphs, with the first line providing a concise summary. The last line in the description should end with a period (.).spring-doc.cadn.net.cn

The JSON object contained in the providers attribute of each hint element can contain the attributes described in the following table:spring-doc.cadn.net.cn

Name Type Purpose

namespring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

The name of the provider to use to offer additional content assistance for the element to which the hint refers.spring-doc.cadn.net.cn

parametersspring-doc.cadn.net.cn

JSON objectspring-doc.cadn.net.cn

Any additional parameter that the provider supports (check the documentation of the provider for more details).spring-doc.cadn.net.cn

Ignored Attributes

The ignored object can contain the attributes shown in the following table:spring-doc.cadn.net.cn

Name Type Purpose

propertiesspring-doc.cadn.net.cn

ItemIgnore[]spring-doc.cadn.net.cn

A list of ignored properties as defined by the ItemIgnore object (described in the next table). Each entry defines the name of the ignored property.spring-doc.cadn.net.cn

The JSON object contained in the properties attribute of each ignored element can contain the attributes described in the following table:spring-doc.cadn.net.cn

Name Type Purpose

namespring-doc.cadn.net.cn

Stringspring-doc.cadn.net.cn

The full name of the property to ignore. Names are in lower-case period-separated form (such as spring.mvc.servlet.path). This attribute is mandatory.spring-doc.cadn.net.cn

Repeated Metadata Items

Objects with the same “property” and “group” name can appear multiple times within a metadata file. For example, you could bind two separate classes to the same prefix, with each having potentially overlapping property names. While the same names appearing in the metadata multiple times should not be common, consumers of metadata should take care to ensure that they support it.spring-doc.cadn.net.cn