手動ヒントの提供

ユーザーエクスペリエンスを向上させ、特定のプロパティの構成をさらに支援するために、次の追加のメタデータを提供できます。

  • プロパティの潜在的な値のリストを記述します。

  • ツールがプロジェクトのコンテキストに基づいて潜在的な値のリストを検出できるように、プロバイダーを関連付けて、明確に定義されたセマンティクスをプロパティに関連付けます。

値ヒント

各ヒントの name 属性は、プロパティの name を参照します。示し最初の例では、spring.jpa.hibernate.ddl-auto プロパティに 5 つの値 nonevalidateupdatecreatecreate-drop を提供します。各値には説明も含まれる場合があります。

プロパティの型が Map の場合、キーと値の両方にヒントを提供できます(ただし、マップ自体には提供できません)。特別な .keys および .values サフィックスは、それぞれキーと値を参照する必要があります。

次の例に示すように、my.contexts がマジック String 値を整数にマッピングすると仮定します。

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

}

マジック値は (この例では) sample1 および sample2 です。キーの追加コンテンツ支援を提供するには、次の JSON をモジュールの手動メタデータに追加します。

{"hints": [
	{
		"name": "my.contexts.keys",
		"values": [
			{
				"value": "sample1"
			},
			{
				"value": "sample2"
			}
		]
	}
]}
代わりに、これら 2 つの値に Enum を使用することをお勧めします。IDE がサポートしている場合、これが自動補完への最も効果的なアプローチです。

バリュープロバイダー

プロバイダーは、セマンティクスをプロパティに付加する強力な方法です。このセクションでは、独自のヒントに使用できる公式プロバイダーを定義します。ただし、お気に入りの IDE はこれらの一部を実装する場合と、まったく実装しない場合があります。また、最終的には独自のものを提供できます。

これは新しい機能であるため、IDE ベンダーはその機能に追いつく必要があります。採用時間は当然異なります。

次の表は、サポートされるプロバイダーのリストをまとめたものです。

名前 説明

any

追加の値の提供を許可します。

class-reference

プロジェクトで使用可能なクラスを自動補完します。通常、target パラメーターで指定された基本クラスによって制約されます。

handle-as

必須の target パラメーターで定義された型で定義されているかのようにプロパティを処理します。

logger-name

有効なロガー名とロガーグループを自動補完します。通常、現在のプロジェクトで使用可能なパッケージ名とクラス名は、定義されたグループと同様に自動補完できます。

spring-bean-reference

現在のプロジェクトで使用可能な Bean 名を自動補完します。通常、target パラメーターで指定された基本クラスによって制約されます。

spring-profile-name

プロジェクトで使用可能な Spring プロファイル名を自動補完します。

特定のプロパティに対してアクティブにできるプロバイダーは 1 つだけですが、すべてのプロバイダーが何らかの方法でプロパティ管理できる場合は、複数のプロバイダーを指定できます。IDE は処理可能な JSON セクションの最初のプロバイダーを使用する必要があるため、最も強力なプロバイダーを最初に配置してください。特定のプロパティのプロバイダーがサポートされていない場合、特別なコンテンツ支援も提供されません。

任意

特別な any provider 値により、追加の値を提供できます。サポートされている場合は、プロパティ型に基づいた定期的な値検証を適用する必要があります。

通常、このプロバイダーは、値のリストがあり、追加の値が有効であると見なされる場合に使用されます。

次の例は、system.state の自動補完値として on および off を提供しています。

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

上記の例では、他の値も許可されています。

クラス参照

クラス参照プロバイダーは、プロジェクトで使用可能なクラスを自動補完します。このプロバイダーは、次のパラメーターをサポートしています。

パラメーター タイプ デフォルト値 説明

target

String (Class)

none

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.

concrete

boolean

true

具象クラスのみを有効な候補と見なすかどうかを指定します。

次のメタデータスニペットは、使用する JspServlet クラス名を定義する標準 server.servlet.jsp.class-name プロパティに対応しています。

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

ハンドル

handle-as プロバイダーを使用すると、プロパティの型をより高レベルの型に置き換えることができます。これは通常、プロパティが java.lang.String 型の場合に発生します。これは、構成クラスがクラスパス上にない可能性のあるクラスに依存しないようにするためです。このプロバイダーは、次のパラメーターをサポートしています。

パラメーター タイプ デフォルト値 説明

target

String (Class)

none

The fully qualified name of the type to consider for the property. This parameter is mandatory.

The following types can be used:

  • Any java.lang.Enum: Lists the possible values for the property. (We recommend defining the property with the Enum type, as no further hint should be required for the IDE to auto-complete the values)

  • java.nio.charset.Charset: Supports auto-completion of charset/encoding values (such as UTF-8)

  • java.util.Locale: auto-completion of locales (such as en_US)

  • org.springframework.util.MimeType: Supports auto-completion of content type values (such as text/plain)

  • org.springframework.core.io.Resource: Supports auto-completion of Spring’s Resource abstraction to refer to a file on the filesystem or on the classpath (such as classpath:/sample.properties)

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 org.springframework.core.io.Resource but cannot be exposed as such, because we need to keep the original String value to pass it to the Liquibase API.

{"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.

This provider supports the following parameters:

Parameter Type Default value Description

group

boolean

true

既知のグループを考慮するかどうかを指定します。

ロガー名は任意の名前にすることができるため、このプロバイダーは任意の値を許可する必要がありますが、プロジェクトのクラスパスで使用できない有効なパッケージ名とクラス名を強調表示できます。

次のメタデータスニペットは、標準の logging.level プロパティに対応しています。キーはロガー名であり、値は標準ログレベルまたは任意のカスタムレベルに対応します。Spring Boot にはすぐに使用できるロガーグループがいくつか定義されているため、専用の値ヒントが追加されています。

{"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 参照

spring-bean-reference プロバイダーは、現在のプロジェクトの構成で定義されている Bean を自動補完します。このプロバイダーは、次のパラメーターをサポートします。

パラメーター タイプ デフォルト値 説明

target

String (Class)

なし

候補者に割り当てられる Bean クラスの完全修飾名。通常、候補ではない Bean を除外するために使用されます。

次のメタデータスニペットは、使用する MBeanServer Bean の名前を定義する標準 spring.jmx.server プロパティに対応しています。

{"hints": [
	{
		"name": "spring.jmx.server",
		"providers": [
			{
				"name": "spring-bean-reference",
				"parameters": {
					"target": "javax.management.MBeanServer"
				}
			}
		]
	}
]}
バインダーはメタデータを認識しません。そのヒントを提供する場合、ApplicationContext を使用して Bean 名を実際の Bean 参照に変換する必要があります。

Spring プロファイル名

spring-profile-name プロバイダーは、現在のプロジェクトの構成で定義されている Spring プロファイルを自動補完します。

次のメタデータスニペットは、有効にする Spring プロファイルの名前を定義する標準 spring.profiles.active プロパティに対応しています。

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