1、首先将如下maven依赖加入pom文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
2、然后在类上加上如下两个注解
@Component
@ConfigurationProperties(prefix = "person")
3、编写配置类
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* 用户配置
* @author 杨红杰
* @date 2020-8-18 9:21
*/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "persion")
public class XzspToolProperties {
private String name;
private intage;
private boolean boss;
}
4、最后运行一下主程序。这样就可以在配置文件中带有提示了