创建SpringBoot工程
这里省略…
pom添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
添加自定义配置类
package com.example.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
//添加此注解后,在idea重新编译项目,在application.properties输入my会有提示
@ConfigurationProperties(prefix = "my")
@Data
@Component
public class MyConfig {
private Integer id;
private String name;
private Integer age;
}