Context: Java + Spring MVC 4.1 web application.
Input:
- configuration.xml
<Configuration>
<rule>
<key></key>
<value></value>
</rule>
...
</Configuration>
Desired behaviour: I would like the XML to be parsed onto a java class bean.
What is the best practice?
What I could do is parse the XML manually via JAXB on a BeanFactory but I was hoping there is a more framework based solution (Reading XMLs seems something that is built into Spring...).
Updated:
Much like reading a properties file: https://stackoverflow.com/a/9260652/885902
and I quote:
<bean id="myProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:my.properties</value>
</list>
</property>
</bean>
and the bean:
@Component
class MyClass {
@Resource(name="myProperties")
private Properties myProperties;
@PostConstruct
public void init() {
// do whatever you need with properties
}
}
Thanks in advance, help is much appreciated :)