Springboot--Cannot prompt about the yml of custom stater

1 Introduction

I encountered a similar situation when building the architecture in the past. When using the @EnableConfigurationProperties annotation, no matter what, the properties in the properties were not automatically prompted when the starter was introduced in the project.

@Data
@ConfigurationProperties(prefix = "properties")
public class DefaultProperties {

    @NestedConfigurationProperty
    public SwaggerProperties swagger;
}

--------以上为properties
properties:
  swagger:
    type: service
    packages: com.wsq.controller
    api-tittle: 'swagger文档'
    service-url:
    writer-name: 'wangqueyue'
    version: '1.0.0'
------无法识别,只能一个个的敲击。

2.Solution

2.1Introduce dependency packages

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-configuration-processor</artifactId>
	<optional>true</optional>
</dependency>

2.2 Placement idea

The creation of spring-configuration-metadata.json is explained online. This file is too cumbersome and it is almost impossible to write it manually, so here is a simple generation method. You only need to modify it after generation.

setting>Build,execution,deployment>Compiker>Annotation Processors

Check Enable annotation processing

2.3 Package and compile starter (key points)

  • You must use maven clean when compiling, otherwise the things you compiled and packaged last time were wrong and you still thought they were correct.
  • Then maven compile (remember, the type of starter must be jar, not pom)
  • maven install, the project must be packaged into a local service.

In the target directory, a spring-configuration-metadata.jsonfile will be generated. There is no need to create it manually. Some files you create in the starter will still be invalid without packaging.

2.4additional-spring-configuration-metadata.json file creation

This file is a supplementary explanation to the previous file, and the creation method is also very simple.

  • Copy the files in the target directory spring-configuration-metadata.jsonto resourcethe directory below META-INF. It does not need to be created directly.
  • Change the file to the name of the title and continue maven clean, compile, and install.
  • A additional-spring-configuration-metadata.jsonfile will be generated in the target directory, so the supplementary file is completed.

Guess you like

Origin blog.csdn.net/wangshiqi666/article/details/130903341