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

来源:互联网 发布:html怎么跟php文件连接 编辑:程序博客网 时间:2024/05/20 12:49

简单的用@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")@Beanpublic BarComponent barComponent() {    ...}

Any property defined with the bar prefix will be mapped onto thatBarComponent beanin a similar manner as the FooProperties example above.


0 0
原创粉丝点击