Spring and JAXB Integration Example
JAXB is an acronym for Java Architecture for XML Binding. It allows java developers to map Java class to XML representation. JAXB can be used to marshal java objects into XML and vice-versa.
It is an OXM (Object XML Mapping) or O/M framework provided by Sun.
Advantage of JAXBNo need to create or use a SAX or DOM parser and write callback methods.
Example of Spring and JAXB Integration (Marshalling Java Object into XML)
You need to create following files for marshalling java object into XML using Spring with JAXB:
Required Jar files
To run this example, you need to load:
download all the jar files for spring including core, web, aop, mvc, j2ee, remoting, oxm, jdbc, orm etc.
If defines three properties id, name and salary. We have used following annotations in this class:
It defines a bean jaxbMarshallerBean where Employee class is bound with the OXM framework.
It gets the instance of Marshaller from the applicationContext.xml file and calls the marshal method.
Output of the exampleemployee.xml
download this example (developed using Myeclipse IDE)
download this example (developed using Eclipse IDE)
Next TopicSpring With Xstream Example