[Spring Boot] Spring Boot Spring Boot Configuration Processor using the complete set custom project properties autocomplete

First, the introduction of coordinates Maven

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

Second, define custom attributes

/**
 * @author zhangboqing
 * @date 2019-11-20
 */
@Component
@ConfigurationProperties(prefix = "my.custom.property")
public class MyCustomProperties {

    private String name;

    private String username;

    private String age;

    @DeprecatedConfigurationProperty(reason = "换名称了",replacement = "username")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
}

Third, after re-compile compile the project, configuration processor creates a JSON file for us: spring-configuration-metadata.json

 

 

 Fourth, and then when we write the configuration in application.properties and application.yml in time there will be an automatic reminder

 

 

Note: Generating spring-configuration-metadata.json file compiled only after the first, reminders to take effect

 

Guess you like

Origin www.cnblogs.com/756623607-zhang/p/11902111.html