简单的用@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.