I have this old-fashion bean defined in xml:
<bean id="configReport" class="com.foo.config.ConfigReport">
<property name="templates">
<map>
<entry key="1">
<list>
<bean p:template="opt1" p:name="OPT1"
class="com.foo.config.ConfigReportTemplate" />
</list>
</entry>
<entry key="-2">
<list>
<bean p:template="opt-2" p:templateExtension="xlsx" p:name="OPT-2"
class="com.foo.config.ConfigReportTemplate" />
</list>
</entry>
</map>
</property>
<property name="defaultTemplate">
<bean p:template="empty" p:name="Empty"
class="com.foo.config.ConfigReportTemplate" />
</property>
</bean>
I would like to replace this bean to work with application.properties
(config) via annotations like in this question. It's ok with plain objects, but for me it's quiet hard to present this <map>
entries in application.properties
Declaration a Map
of properties in a simple application.properties
format looks like a mess, I can suggest you consider a using of JSON format for these properties. It provides a more readable view, something like this:
{
"reportTemplates": {
1: {
"template": "com.foo.config.FirstTemplate",
"name": "OPT1"
},
2: {
"template": "com.foo.config.SecondTemplate",
"name": "OPT2"
},
"KEY" : {
"field":"value"
},
...
}
}
And now you can use this config file in a java configuration to build necessary templates.
You can read how to work with JSON properties in Spring here : https://www.baeldung.com/spring-boot-json-properties