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

提供手动提示

为了改善用户体验并进一步帮助用户配置给定属性,您可以提供其他元数据,以便:spring-doc.cadn.net.cn

值提示

name属性引用name的财产。 在前面显示的初始示例中,我们为spring.jpa.hibernate.ddl-auto财产:none,validate,update,createcreate-drop. 每个值也可能具有说明。spring-doc.cadn.net.cn

如果您的属性为Map中,你可以为 key 和 values 提供提示(但不能为 map 本身提供提示)。 特别的.keys.valuessuffixes 必须分别引用 keys 和 values。spring-doc.cadn.net.cn

假设my.contexts地图魔术Stringvalues 设置为 integer,如以下示例所示:spring-doc.cadn.net.cn

import java.util.Map;

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

@ConfigurationProperties("my")
public class MyProperties {

	private Map<String, Integer> contexts;

	// getters/setters ...

	public Map<String, Integer> getContexts() {
		return this.contexts;
	}

	public void setContexts(Map<String, Integer> contexts) {
		this.contexts = contexts;
	}

}

The magic values are (in this example) are sample1 and sample2. In order to offer additional content assistance for the keys, you could add the following JSON to the manual metadata of the module:spring-doc.cadn.net.cn

{"hints": [
	{
		"name": "my.contexts.keys",
		"values": [
			{
				"value": "sample1"
			},
			{
				"value": "sample2"
			}
		]
	}
]}
We recommend that you use an Enum for those two values instead. If your IDE supports it, this is by far the most effective approach to auto-completion.

Value Providers

Providers are a powerful way to attach semantics to a property. In this section, we define the official providers that you can use for your own hints. However, your favorite IDE may implement some of these or none of them. Also, it could eventually provide its own.spring-doc.cadn.net.cn

As this is a new feature, IDE vendors must catch up with how it works. Adoption times naturally vary.

The following table summarizes the list of supported providers:spring-doc.cadn.net.cn

Name Description

anyspring-doc.cadn.net.cn

Permits any additional value to be provided.spring-doc.cadn.net.cn

class-referencespring-doc.cadn.net.cn

Auto-completes the classes available in the project. Usually constrained by a base class that is specified by the target parameter.spring-doc.cadn.net.cn

handle-asspring-doc.cadn.net.cn

Handles the property as if it were defined by the type defined by the mandatory target parameter.spring-doc.cadn.net.cn

logger-namespring-doc.cadn.net.cn

Auto-completes valid logger names and logger groups. Typically, package and class names available in the current project can be auto-completed as well as defined groups.spring-doc.cadn.net.cn

spring-bean-referencespring-doc.cadn.net.cn

Auto-completes the available bean names in the current project. Usually constrained by a base class that is specified by the target parameter.spring-doc.cadn.net.cn

spring-profile-namespring-doc.cadn.net.cn

Auto-completes the available Spring profile names in the project.spring-doc.cadn.net.cn

Only one provider can be active for a given property, but you can specify several providers if they can all manage the property in some way. Make sure to place the most powerful provider first, as the IDE must use the first one in the JSON section that it can handle. If no provider for a given property is supported, no special content assistance is provided, either.

Any

The special any provider value permits any additional values to be provided. Regular value validation based on the property type should be applied if this is supported.spring-doc.cadn.net.cn

This provider is typically used if you have a list of values and any extra values should still be considered as valid.spring-doc.cadn.net.cn

The following example offers on and off as auto-completion values for system.state:spring-doc.cadn.net.cn

{"hints": [
	{
		"name": "system.state",
		"values": [
			{
				"value": "on"
			},
			{
				"value": "off"
			}
		],
		"providers": [
			{
				"name": "any"
			}
		]
	}
]}

Note that, in the preceding example, any other value is also allowed.spring-doc.cadn.net.cn

Class Reference

The class-reference provider auto-completes classes available in the project. This provider supports the following parameters:spring-doc.cadn.net.cn

Parameter Type Default value Description

targetspring-doc.cadn.net.cn

String (Class)spring-doc.cadn.net.cn

nonespring-doc.cadn.net.cn

The fully qualified name of the class that should be assignable to the chosen value. Typically used to filter out-non candidate classes. Note that this information can be provided by the type itself by exposing a class with the appropriate upper bound.spring-doc.cadn.net.cn

concretespring-doc.cadn.net.cn

booleanspring-doc.cadn.net.cn

truespring-doc.cadn.net.cn

Specify whether only concrete classes are to be considered as valid candidates.spring-doc.cadn.net.cn

The following metadata snippet corresponds to the standard server.servlet.jsp.class-name property that defines the class name to use must be an HttpServlet:spring-doc.cadn.net.cn

{"hints": [
	{
		"name": "server.servlet.jsp.class-name",
		"providers": [
			{
				"name": "class-reference",
				"parameters": {
					"target": "jakarta.servlet.http.HttpServlet"
				}
			}
		]
	}
]}

Handle As

The handle-as provider lets you substitute the type of the property to a more high-level type. This typically happens when the property has a String type, because you do not want your configuration classes to rely on classes that may not be on the classpath. This provider supports the following parameters:spring-doc.cadn.net.cn

Parameter Type Default value Description

targetspring-doc.cadn.net.cn

String (Class)spring-doc.cadn.net.cn

nonespring-doc.cadn.net.cn

The fully qualified name of the type to consider for the property. This parameter is mandatory.spring-doc.cadn.net.cn

The following types can be used:spring-doc.cadn.net.cn

If multiple values can be provided, use a Collection or Array type to teach the IDE about it.

The following metadata snippet corresponds to the standard spring.liquibase.change-log property that defines the path to the changelog to use. It is actually used internally as a Resource but cannot be exposed as such, because we need to keep the original String value to pass it to the Liquibase API.spring-doc.cadn.net.cn

{"hints": [
	{
		"name": "spring.liquibase.change-log",
		"providers": [
			{
				"name": "handle-as",
				"parameters": {
					"target": "org.springframework.core.io.Resource"
				}
			}
		]
	}
]}

Logger Name

The logger-name provider auto-completes valid logger names and logger groups. Typically, package and class names available in the current project can be auto-completed. If groups are enabled (default) and if a custom logger group is identified in the configuration, auto-completion for it should be provided. Specific frameworks may have extra magic logger names that can be supported as well.spring-doc.cadn.net.cn

This provider supports the following parameters:spring-doc.cadn.net.cn

Parameter Type Default value Description

groupspring-doc.cadn.net.cn

booleanspring-doc.cadn.net.cn

truespring-doc.cadn.net.cn

Specify whether known groups should be considered.spring-doc.cadn.net.cn

Since a logger name can be any arbitrary name, this provider should allow any value but could highlight valid package and class names that are not available in the project’s classpath.spring-doc.cadn.net.cn

The following metadata snippet corresponds to the standard logging.level property. Keys are logger names, and values correspond to the standard log levels or any custom level. As Spring Boot defines a few logger groups out-of-the-box, dedicated value hints have been added for those.spring-doc.cadn.net.cn

{"hints": [
	{
		"name": "logging.level.keys",
		"values": [
			{
				"value": "root",
				"description": "Root logger used to assign the default logging level."
			},
			{
				"value": "sql",
				"description": "SQL logging group including Hibernate SQL logger."
			},
			{
				"value": "web",
				"description": "Web logging group including codecs."
			}
		],
		"providers": [
			{
				"name": "logger-name"
			}
		]
	},
	{
		"name": "logging.level.values",
		"values": [
			{
				"value": "trace"
			},
			{
				"value": "debug"
			},
			{
				"value": "info"
			},
			{
				"value": "warn"
			},
			{
				"value": "error"
			},
			{
				"value": "fatal"
			},
			{
				"value": "off"
			}

		],
		"providers": [
			{
				"name": "any"
			}
		]
	}
]}

Spring Bean Reference

The spring-bean-reference provider auto-completes the beans that are defined in the configuration of the current project. This provider supports the following parameters:spring-doc.cadn.net.cn

Parameter Type Default value Description

targetspring-doc.cadn.net.cn

String (Class)spring-doc.cadn.net.cn

nonespring-doc.cadn.net.cn

The fully qualified name of the bean class that should be assignable to the candidate. Typically used to filter out non-candidate beans.spring-doc.cadn.net.cn

The following metadata snippet corresponds to the standard spring.jmx.server property that defines the name of the MBeanServer bean to use:spring-doc.cadn.net.cn

{"hints": [
	{
		"name": "spring.jmx.server",
		"providers": [
			{
				"name": "spring-bean-reference",
				"parameters": {
					"target": "javax.management.MBeanServer"
				}
			}
		]
	}
]}
The binder is not aware of the metadata. If you provide that hint, you still need to transform the bean name into an actual Bean reference using by the ApplicationContext.

Spring Profile Name

The spring-profile-name provider auto-completes the Spring profiles that are defined in the configuration of the current project.spring-doc.cadn.net.cn

The following metadata snippet corresponds to the standard spring.profiles.active property that defines the name of the Spring profile(s) to enable:spring-doc.cadn.net.cn

{"hints": [
	{
		"name": "spring.profiles.active",
		"providers": [
			{
				"name": "spring-profile-name"
			}
		]
	}
]}