I have a Spring boot application that defines some endpoints in the application.yml config file. The YAML contains multiple documents, one for each profile.
I would like to run a Gradle task before starting the application. The Gradle task is passed the profile as an argument. It should use the endpoints defined in the configuration for that profile.
How can I load the value from the configuration without loading the entire Spring framework?
Example
# src/main/resources/application.yml
endpoints:
foo: localhost:12345/foo
bar: localhost:12345/bar
---
spring.profiles: staging
endpoints:
foo: dev.foo.com/api
bar: dev.bar.com/api
---
spring.profiles: production
endpoints:
foo: foo.com/api
bar: bar.com/api
public class Task {
public static void main(String[] args) {
String profile = arg[0];
// TODO load endpoints from src/main/resources/application.yml
Map<String, Object> endpoints = ...
System.out.println(endpoints.get("foo");
}
}