您的位置:首页 > 编程语言 > Java开发

spring 的属性获取,取值.注解下的类和配置分离.

2016-12-21 15:51 288 查看
简单的用@value 复杂的用

@ConfigurationProperties("foo")

https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-typesafe-configuration-properties https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-vs-value
注解下:

类和配置分离.

24.7.1 Third-party configuration

As well as using
@ConfigurationProperties
to annotate a class, you can also use iton public
@Bean
methods. This can be particularly useful when you want to bindproperties to third-party components that are outside of your control.

To configure a bean from the
Environment
properties, add
@ConfigurationProperties
toits bean registration:

@ConfigurationProperties(prefix = "bar")
@Bean
public BarComponent barComponent() {
...
}

Any property defined with the
bar
prefix will be mapped onto that
BarComponent
beanin a similar manner as the
FooProperties
example above.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐