Reputation: 143
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).
Currently I have a application.yaml that looks like this
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.
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!
Upvotes: 2
Views: 5007
Reputation: 645
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.
The active profile can be specified when starting your jar. You can e.g. specify the active profile via command line: --spring.profiles.active=dev,hsqldb
. See the documentation for more information.
Upvotes: 2