SpringBoot 在线文档地址

SpringBoot 在线文档地址

SpringBoot 在线文档地址

英文版
中文版

15.1 在main函数类中使用@Import注解

1
You need not put all your @Configuration into a single class. The @Import annotation can be used to import additional configuration classes. Alternatively, you can use @ComponentScan to automatically pick up all Spring components, including @Configuration classes.

释义:
您无需将所有@Configuration放入单个类中。 @Import注释可用于导入其他配置类。或者,您可以使用@ComponentScan自动获取所有Spring组件,包括@Configuration类。

24.56 使用Java类加载 配置文件参数值

配置类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
	@ConfigurationProperties("foo")
public class FooProperties {

private final List<MyPojo> list = new ArrayList<>();

public List<MyPojo> getList() {
return this.list;
}

}
```
* 注: 推荐使用构造函数的方式注入属性值

> 配置文件

```yml
foo:
list:
- name: my name
description: my description
---
spring:
profiles: dev
foo:
list:
- name: my another name