spring_reference/IV. Spring Boot features/23.7.1. Third-party configu...

14 lines
569 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 23.7.1. 第三方配置
正如使用@ConfigurationProperties注解一个类你也可以在@Bean方法上使用它。当你需要绑定属性到不受你控制的第三方组件时这种方式非常有用。
为了从Environment属性配置一个bean将@ConfigurationProperties添加到它的bean注册过程
```java
@ConfigurationProperties(prefix = "foo")
@Bean
public FooComponent fooComponent() {
...
}
```
和上面ConnectionSettings的示例方式相同任何以foo为前缀的属性定义都会被映射到FooComponent上。