XML Marshalling
2023. 7. 19. 19:19ㆍ개발자료/Spring Framework
반응형
Marshalling
메모리에 있는 객체를 특정한 데이터 형식으로 변황하는 과정
pom.xml
spring-oxm, xstrream 등록
<!-- spring oxm -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<!-- xstream core -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.7</version>
</dependency>
※ spring-oxm 은 spring-framework 버전과 동일해야 한다.
servlet-context.xml
아래 두개 항목은 필수로 추가되어야 한다.
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/oxm"
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/oxm">
...
<!-- XStream -->
<beans:bean id="xstreamMarshaller"
class="org.springframework.oxm.xstream.XStreamMarshaller">
<beans:property name="autodetectAnnotations" value="true" />
</beans:bean>
<!-- xmlView -->
<beans:bean id="xmlView"
name="xmlView"
class="org.springframework.web.servlet.view.xml.MarshallingView">
<beans:property name="marshaller" ref="xstreamMarshaller" />
<beans:property name="contentType" value="application/xml;charset=UTF-8" />
<beans:property name="modelKey" value="xmlData" />
</beans:bean>
...
</beans:beans>
반응형