zl程序教程

您现在的位置是:首页 >  后端

当前栏目

spring boot的配置文件的代码自动提示

2023-09-27 14:25:59 时间

在这里插入图片描述

package com.superjson.common.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "person")
@Data
public class Person {

    String name ;
    String no;
}

有时,我们编写自定义配置类,需要在配置文件中添加配置信息,比如配置perosn类中的no, name属性。只要在ymal文件中输入person,它的属性就可以自动提示。实现这个功能,我们需要在pom文件中添加如下代码:

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

但是,它只是提示代码的功能,对我们的业务没多大作用,因而,我们在打包时,可以不用将它打进去,这样可以节约空间,因而,我们可以配置如下代码,即可在打包时,剔除该jar包:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
            </exclude>
        </excludes>
    </configuration>
</plugin>