spring boot 读取配置文件
通过@ConfigurationProperties方式
```java 读取配置文件 import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;
@Component @ConfigurationProperties(prefix = "bill") public class BillActivitiConfig {
@Getter
@Setter
private static RoleId roleId;
@Getter
@Setter
private static Email email;
@Getter
@Setter
public static class RoleId {
private String cal;
private String convert;
private String push;
}
@Getter
@Setter
public static class Email {
private String receiver;
private String cc;
}}
ConfigurationProperties 注解需要添加依赖
```xml pom.xml
org.springframework.boot spring-boot-configuration-processor true ```
Last updated