Article From:

SpringBootCustom configuration

springbootHere it’s just a lot of introduction, everyone should know the springboot zero configuration file, so the configuration information is assembled in the property files (properties, YML, yaml), and sometimes we need to define some of the configuration, and then the small editor briefly introduces the SPringboot custom configuration.


Configuration class

First, @Configuration and @ConfigurationProperties are added to the configuration class.

package com.bdqn.lyrk.ytl.springbootstarteralipay.config;

import org.springframework.context.annotation.Configuration;

 * Created By Yang Tianle on 2018/5/20*/
@ConfigurationProperties(prefix = "alipay.config")
public class AliPayConfig {

    // Business appid
    private String appId;

    public String getAppId() {
        return appId;

    public void setAppId(String appId) {
        this.appId = appId;

View Code

@ConfigurationPropertiesWhat is the beginning of the parameter in it?

In fact, a simple configuration class is configured.

Attribute file automatic prompt

Usually in our development, attribute files will generate an automatic prompt. This custom prompt can also add our configuration class to the prompt.

First, we need to add processor jar package to the project.

dependencies {
    compileOnly "org.springframework.boot:spring-boot-configuration-processor"

View Code

In the second step, we need to configure the META-INF/spring-configuration-metadata.json file to describe it. But the amount of code is very large. For convenience, we can generate it through IDE, and here is idea.

Search for Annotation Processors in idea settings, then Enable annonation processing is finished.

We can see automatically generated spring-configuration-metadata.json in the compiled file.

Attached map:


Link of this Article: Custom configuration of Springboot

Leave a Reply

Your email address will not be published. Required fields are marked *