<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-auto</artifactId>
</dependency>
添加注解
//lombok的注解,自动生成getter/setter
@Data
//用来将properties和yml配置文件属性转化为bean对象使用
@ConfigurationProperties(prefix = "bluesky")
import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Data
@ConfigurationProperties(prefix = "bluesky")
public class BlueskyDbProperties {
/**
* jdbc驱动
*/
private String driverName;
}
字段注释写清楚,方便在yml中提示清楚
添加注解
//mica-auto通过识别该注解自动生成文件
@AutoConfiguration
//使ConfigurationProperties注解生效
@EnableConfigurationProperties(BlueskyDbProperties.class)
@AutoConfiguration
@EnableConfigurationProperties(BlueskyDbProperties.class)
public class ConnectionPool {
@Resource
private BlueskyDbProperties blueskyDbProperties;
}
使用实体属性,需要通过@Resource注解注入使用
直接注入ConnectionPool即可使用里面方法