[英]spring profiles in .yaml. How do you set up configuration properties?
I am a spring newbie and a .yaml newbie as well and I´m starting to get cross eyed googling answers(a lot of them are very outdated or just confusing). 我既是春季新手,也是.yaml新手,并且我开始cross目结舌地搜索答案(其中很多都非常过时或令人困惑)。
Currently I have a application.yaml that looks like this 目前我有一个application.yaml看起来像这样
spring:
profiles.active: TEST
---
spring:
profiles: DEV
logging:
level:
org.springframework.web: INFO
se.some.url: DEBUG
api:
url:
one: test.url
two : test.url
certification:
policies:
one : 0.0.0.0.0
two : 0.0.30.0
---
spring:
profiles: TEST
logging:
level:
org.springframework.web: INFO
se.some.url: DEBUG
api:
url:
one: test.url
two : test.url
certification:
policies:
one : 0.0.0.0.0
two : 0.0.30.0
I need to be able to use the values of the certification.policies and api.url in my code and make sure everything loads depending on with profile is active. 我需要能够在我的代码中使用certificate.policies和api.url的值,并确保根据配置文件加载的所有内容均处于活动状态。
I do get that a config class needs to be created. 我确实知道需要创建一个配置类。
But what annotation should be used? 但是应该使用什么注释? How do I set the profile? 如何设置个人资料? How do I get the value? 我如何获得价值?
Grateful for any help! 感谢您的帮助!
You should read this documentation about externalized configuration . 您应该阅读有关外部化配置的文档 。
With @ConfigurationProperties("some-property")
you tell Spring to initialize the fields with the values configured in your .yml
file. 使用@ConfigurationProperties("some-property")
您告诉Spring使用.yml
文件中配置的值初始化字段。
The active profile can be specified when starting your jar. 启动jar时可以指定活动配置文件。 You can eg specify the active profile via command line: --spring.profiles.active=dev,hsqldb
. 您可以例如通过命令行指定活动配置文件:-- --spring.profiles.active=dev,hsqldb
。 See the documentation for more information. 请参阅文档以获取更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.