# spring boot 读取配置文件

[四种读取properties文件的方式](https://www.imooc.com/article/18252)

## 通过@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;
}
```

}

````
```properties application-dev.properties
# bill
# 这里注意java文件中属性名是驼峰大小写，写到配置文件应该使用 ‘-’ 分割的全小写
bill.role-id.cal=21
bill.role-id.convert=22
bill.role-id.push=23
#notify email
bill.email.receiver=zhanghao6@kingsoft.com
bill.email.cc=GUOMEINA@kingsoft.com
````

ConfigurationProperties 注解需要添加依赖

\`\`\`xml pom.xml

&#x20;org.springframework.boot spring-boot-configuration-processor true \`\`\`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.rizon.top/springboot/springboot-du-qu-pei-zhi-wen-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
