AI & Machine Learning
OXM in Spring
Last updated on Jun 15, 2020
Copy Link:
Spring and JAXB Integration
JAXB is an acronym for Java Architecture for XML Binding. It enables java engineers to delineate class to XML portrayal. JAXB can be utilized to marshal java objects into XML and the other way around.It is an OXM (Object XML Mapping) or O/M structure gave by Sun.
Preferred standpoint of JAXB No compelling reason to make or utilize a SAX or DOM parser and compose callback strategies.- Employee.java
- applicationContext.xml
- Client.java
- Spring Core jar files
- Spring Web jar files
JAVA Tutorial Video
[embed]https://www.youtube.com/watch?v=Mb8nG-NH6gg&t=2835s[/embed] Employee.java- @XmlRootElement It specifies the root element for the xml file.
- @XmlAttribute It specifies attribute for the property.
- @XmlElement It specifies the element.
Output
employee.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <employee id="101"> <name>Sonoo Madhu</name> <salary>100000.0</salary> </employee> Spring with Xstream Xstream is a library to serialize articles to xml and the other way around without necessity of any mapping document. Notice that castor requires a mapping record. XStreamMarshaller class gives office to marshal objects into xml and the other way around.Spring with Castor:
By the assistance of Castor Marshaller class, we can marshal the java objects into xml and the other way around utilizing castor. It is the usage class for Marshaller and Unmarshaller interfaces. It doesn't require any further arrangement by default.Spring and Castor Integration (Marshalling Java Object into XML)
- Employee.java
- applicationContext.xml
- mapping.xml
- Client.java
Required Jar files
To run this example, you need to load:- Spring Core jar files
- Spring Web jar files
- castor-1.3.jar
- castor-1.3-core.jar
- Make struts2 application and include spring container records.
- In web.xml record, characterize ContextLoaderListener class.
- In struts.xml record, characterize bean name for the activity class.
- In the activity class, characterize additional property e.g. message.
Spring and Struts 2 Integration
- index.jsp
- web.xml
- struts.xml
- applicationContext.xml
- Login.java
- welcome.jsp
- error.jsp
