0

Context: Java + Spring MVC 4.1 web application.

Input:

  1. 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 :)

Community
  • 1
  • 1
henryabra
  • 1,433
  • 1
  • 10
  • 15
  • have a look at this http://www.mkyong.com/spring3/spring-objectxml-mapping-example/ – Vihar May 18 '15 at 10:00
  • The proposed link has an example of manual XML marshaling/unmarshaling using castor... I was hoping for something with JAXB and built into the framework much like reading a properties file: http://stackoverflow.com/a/9260652/885902 – henryabra May 18 '15 at 10:27

0 Answers0