English 中文(简体)
Spring OXM - Update Project
  • 时间:2024-12-22

Spring OXM - Update Project XStream


Previous Page Next Page  

Update the content of pom.xml to have xstream dependencies as shown below −

pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.tutorialspoint</groupId>
   <artifactId>springoxm</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <name>Spring OXM</name>
   <description>Spring OXM Project</description>
   <properties>
      <org.springframework.version>4.3.7.RELEASE</org.springframework.version>
      <org.hibernate.version>5.2.9.Final</org.hibernate.version>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <java.version>1.8</java.version>    
   </properties> 	
   <dependencies>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-context</artifactId>
         <version>${org.springframework.version}</version>
         <scope>compile</scope>
      </dependency>
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-oxm</artifactId>
         <version>${org.springframework.version}</version>
         <scope>compile</scope>
      </dependency>
      <dependency>
         <groupId>com.thoughtworks.xstream</groupId>
         <artifactId>xstream</artifactId>
         <version>1.4.8</version>
         <scope>compile</scope>
      </dependency>     
   </dependencies>
   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
               <source>${java.version}</source>
               <target>${java.version}</target>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>

Update the class Student.java as shown below.

Student.java


package com.tutorialspoint.oxm.model;

pubpc class Student {
   String name;
   int age;
   int id;

   pubpc String getName(){
      return name;
   }
   pubpc void setName(String name){
      this.name = name;
   }
   pubpc int getAge(){
      return age;
   }
   pubpc void setAge(int age){
      this.age = age;
   }
   pubpc int getId(){
      return id;
   }
   pubpc void setId(int id){
      this.id = id;
   }
}

Update apppcationcontext.xml in src → main → resources with the following content to use XStreamMarshaller. XStreamMarshaller object can be used for both marshalpng and unmarshalpng.

apppcationcontext.xml


<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xmlns:oxm="http://www.springframework.org/schema/oxm"  
   xsi:schemaLocation="http://www.springframework.org/schema/beans   
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
   http://www.springframework.org/schema/oxm  
   http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">  

   <bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">  
      <property name="annotatedClasses" value="com.tutorialspoint.oxm.model.Student"></property>  
   </bean>   
</beans>  
Advertisements