The Spring Boot JAR contains metadata files that provide details of all supported configuration properties. This file is designed to allow IDE developers to provide context-specific help and “code completion.” Summary this article hopes to be engaged in the relevant work of the students can help or inspire.

The background,

Reaction-steams is a spring-boot source package

  • spring-configuration-metadata.json

  • additional-spring-configuration-metadata.json

To be honest, metadata is the main thing that appeals to me, as metadata management has been really struggling with tweaking the engine lately.

SpringBoot is a metadata configuration extension provided by SpringBoot, but the metadata here is not similar to metadata managed only in Spring bean.

Bradley Bradley 2008 official explanation

IO /spring-boot…

The simple point can be understood as the configuration of this kind of metadata, so that we can use the application. Properties or application. Yml configuration in the process of using IDEA more annotation, more convenient for us to develop and use.

Police Officer 2008

Take our usual logging configuration as an example

  • Metadata Configuration

  • Define the configuration

2. Application examples

Bradley J. 2008 plug-in Factory configuration definition

The configuration metadata file is located under the JAR. META-INF/spring-configuration-metadata.json They use a simple JSON format where the items are grouped under ‘groups’ or’ properties’

{ "properties": [ { "name": "plugin-cache.basePackage", "type": "java.lang.String", "description": }, {"name": "plugin-cache.title", "type": "java.lang.String", "description": "Plugin Cache factory "}, {"name": "plugin-cache.description", "type": "java.lang.String", "description": "Plugin Factory Description"}, {"name": "plugin-cache.version", "type": "java.lang.String", "defaultValue": "V1.0", "description": "Version."}]}Copy the code

Most metadata files are generated automatically at compile time by processing all annotated items

View the previous article at @ConfigurationProperties

@ EnableConfigurationProperties works

Refer to the properties table below for configuration understanding.

Deprecation JSON objects contained in the attributes of each properties element can contain the following attributes:

J. J. Bradley plug-ins Factory configuration injection

@Data @Component @ConfigurationProperties(PluginCacheProperties.PREFIX) class PluginCacheProperties { public static final String PREFIX = "plugin-cache"; /** * private String basePackage = ""; /** * private String title = "Plugin "; /** * private String Description = "Plug-in cache description "; /** * version */ private String version = "V1.0"; /** * default encoding */ private String charset=" utF-8 "; }Copy the code

2008 Configuration App

Third, summary

Metadata configuration is not hard to understand! Mainly for the component library in order to allow users to optimize the use of a set of IDEA prompts. In this way, when we open private components or plug-ins, we can provide open capability for configuration items, and improve IDEA prompts according to metadata configuration. In this way, other users can quickly know the configuration type of the corresponding parameter and the related configuration attribute description. Summary this article hopes to be engaged in the relevant work of the students can help or inspire

Phase to recommend

  • Spring Boot implements 4 ways of universal Auth authentication

  • Use of the @EventListener annotation and how it works

  • How to standardize your Git submission format?

  • Micro service architecture | how to make the interface permission to continue to inherit?

  • Java 18 is coming. You’re not still using Java 8, are you?