I know that you can override yaml config values with placeholders like so:
some-setting: ${SOME_SETTING:default value}
And I know that you can express lists of objects like so:
customers:
- name: acme
category: manufacturing
employees: 200
- name: virtucon
category: evil
employees: 1
So how would I express such a list via the ${} placeholder notation?
You would have to create a ConfigurationProperties to read in the property objects.
@Component
@ConfigurationProperties("app")
public class AppProperties {
private List<Customer> customers = new ArrayList<>();
public static class Customer {
private String name;
private String category;
private int employees;
}
}
Usually you would also create a prefix for this in your .yml file also
app:
customers:
- name: acme
category: manufacturing
employees: 200
- name: virtucon
category: evil
employees: 1
You can now auto-wire this class anywhere in your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With