2
votes

I have a DefaultProcessor.java that processes files for different products (some 50 products). So the product specific beans are configured in spring config files (one spring-config file per product).

Now I have some 2-3 product-specific properties (key-value pairs) also. So I was wondering to have those properties in the config file itself instead of having one properties file per product.

Q1. Is it possible to specify key-value pairs in spring-config file without creating a bean?

Q2. If it is not possible, then Is it a good practice to create an Environment.java class having Map<String, String> as a property and then configure that bean in each product-specific config file instead of having those properties in a .properties file.

1

1 Answers

4
votes

You can use util:map

From the spring docs:

<util:map id="emails">
    <entry key="pechorin" value="[email protected]"/>
    <entry key="raskolnikov" value="[email protected]"/>
    <entry key="stavrogin" value="[email protected]"/>
    <entry key="porfiry" value="[email protected]"/>
</util:map>

You can then inject the map using normal spring setter/constructor mechanisms