If you are not limited and have the flexibility to determine how your properties are configured, there are two options.
First, you just need to define the Beans in Java code in the @Configuration class. For most objects, you can have Beans that are @Autowired. All Beans are loaded only at runtime. For Maps (and lists, etc.) you define them as Beans and then access them using the @Resource annotation. Note that you cannot access Maps with @Autowired, Spring uses @Resource for these types.
Unlike the comment on the other answer, I argue that settings can also be defined in the code, just because it is written in XML does not make it different, they are considered equivalent. By writing your preferences and settings in Java, you get the power of OOP, which is fantastic when you have a complex configuration.
Bean ad example:
@Bean public MyConfig myConfig() { final MyConfig myConfig = new MyConfig(); myConfig.put("configA", "A"); ... return myConfig; } @Bean public Map<String, String> myMap() { final Map<String, String> myMap = new HashMap<>(); myMap.put("A", "a"); return myMap; }
Usage example:
@Autowired private MyConfig myConfig; @Resource(name = "myMap") private Map<String, String> myMap;
Secondly, you should use the global system properties defined in the properties file. You can write properties in YAML or a map type configuration. Details in the provided link. Edit You can proxy your properties and then refer to them using the @Value annotation. You can have collections in YAML.
application.properties
myConfig.configA:A myConfig.configB:B myConfig.coll.cA:['a','b','c'] myConfig.coll.cB:{a:A,b:B,c:C} ...
In code
@Value("${myConfig.configA}") private String configA;