I have a application.properties file that needs some dynamic keys, which allow at least one level of nesting. In technical terms, the application starts and I am able to read those values, but the metadata doesn't seem to work correctly, because IntelliJ Ultimate is giving me some errors:
Cannot resolve property 'foo' in java.util.Map
# Static property
com.company.version=1.0
# Dynamic property, starting after products
com.company.products.first.foo=firstFoo
com.company.products.first.bar=firstBar
com.company.products.second.foo=SecondFoo
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@Configuration
@ConfigurationProperties(prefix = "com.company")
public class Properties {
private String version;
private Map<String, Map<String, ArrayList<String>>> products = new HashMap<>();
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Map<String, Map<String, ArrayList<String>>> getProducts() {
return products;
}
public void setProducts(Map<String, Map<String, ArrayList<String>>> products) {
this.products = products;
}
}
In additional I would like to know what the best practice would be to read those values. For "normal" static properties I used the Environment that I autowire in the constructor, but that is – as far as I know – unable to read the products map. Thats why I autowire my Properties class and use the getProducts function.
Thanks a lot for your help!