zoukankan      html  css  js  c++  java
  • Spring boot 自定义配置实现自动提示

    Spring boot 自定义配置实现自动提示

    这个是基于IDE来做的,Eclipse的没有试验过

    1、新建一个配置类(ExampleProperties)

    package org.yujuan.springbootlearning.properties;
    
    import lombok.Data;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    
    @Data
    @ConfigurationProperties(prefix = "example")
    public class ExampleProperties {
        /**姓名**/
        private String name;
        /**路径**/
        private String path;
        /**是否开启*/
        private Boolean enable;
    }
    @value 没有这个作用。

    2、引入依赖spring-boot-configuration-processor

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.7.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>org.yujuan</groupId>
        <artifactId>springboot-learning</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <name>springboot-learning</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.8</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <optional>true</optional>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    3、修改IDE的配置

    打开设置页面,按照箭头所指示的地方开启Enable annotation processing
    修改IDE配置

    4、重新编译

    会在target目录下的META_INF 下生成spring-configuration-metadata.json文件,同时在配置文件写填写配置时,会自动提示。如下图:
    效果图
    效果图

    项目地址 Github springboot-configuation-auto-tips 分支

  • 相关阅读:
    CF580B Kefa and Company 尺取法
    [USACO08OCT]牧场散步Pasture Walking BZOJ1602 LCA
    [USACO09FEB]改造路Revamping Trails 分层最短路 Dijkstra BZOJ 1579
    [USACO09OPEN]牛的数字游戏Cow Digit Game 博弈
    Codeforces 628F 最大流转最小割
    Codeforces 513D2 Constrained Tree
    Codeforces 1009G Allowed Letters 最大流转最小割 sosdp
    Codeforces 431E Chemistry Experiment 线段树 + 二分
    Codeforces 359E Neatness
    Codeforces 1045B Space Isaac
  • 原文地址:https://www.cnblogs.com/cuiqq/p/12101070.html
Copyright © 2011-2022 走看看