VI=Visa
MC=Mastercard
...
Can I automatically inject this into a Map<String, String>
with Spring
?
Like:
@Resource("${myfile.properties}")
private Map<String, String> creditcards;
Is that possible?
VI=Visa
MC=Mastercard
...
Can I automatically inject this into a Map<String, String>
with Spring
?
Like:
@Resource("${myfile.properties}")
private Map<String, String> creditcards;
Is that possible?
Found a nice feature:
@Bean(name = "credit")
public PropertiesFactoryBean mapper() {
PropertiesFactoryBean bean = new PropertiesFactoryBean();
bean.setLocation(new ClassPathResource("credit.properties"));
return bean;
}
inject it anywhere as follows:
@Resource(name = "credit")
private Properties credit;
Did you saw this: How to inject a Map using the @Value Spring Annotation?
Here in the Question the person uses a map. So perhaps you can use this? Otherwise you can use the Properties class (https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html) and if you really need a map, you can transform the properties-object to a map