24.7.1 Third-party configuration

@ConfigurationProperties不仅可以注解在类上,也可以注解在public @Bean方法上,当你需要为不受控的第三方组件绑定属性时,该方法将非常有用。

为了从Environment属性中配置一个bean,你需要使用@ConfigurationProperties注解该bean:

@ConfigurationProperties(prefix = "bar")
@Bean
public FooComponent fooComponent() {
    ...
}

24.7 Type-safe Configuration PropertiesFooProperties的示例方式相同,所有以bar为前缀的属性定义都会被映射到BarComponent上。

results matching ""

    No results matching ""