【发布时间】:2015-08-23 07:12:58
【问题描述】:
我正在编写一个 Spring Web 应用程序,并希望将我的对象转换为没有注释的 xml。我知道使用 xml 配置可以做到这一点:
<bean id="jaxb2Marshaller" class="software.bytepushers.userprofile.models.JaxbIntroductionsMarshaller">
<property name="classesToBeBound">
<list>
<value>software.bytepushers.userprofile.models.Person</value>
<value>software.bytepushers.userprofile.models.WebServiceResponse</value>
</list>
</property>
<property name="jaxbContextProperties">
<map>
<entry>
<key>
<util:constant static-field="com.sun.xml.bind.api.JAXBRIContext.ANNOTATION_READER"/>
</key>
<bean class="org.jboss.jaxb.intros.IntroductionsAnnotationReader">
<constructor-arg ref="jaxbIntroductions"/>
</bean>
</entry>
</map>
</property>
<property name="schema" value="classpath:schemas/avs-pdf-query-request.xsd"/>
</bean>
<bean id="jaxbIntroductions" class="org.jboss.jaxb.intros.IntroductionsConfigParser"
factory-method="parseConfig">
<constructor-arg><value>classpath:spring/jaxb-intros-marshaller-mapping.xml</value></constructor-arg>
</bean>
现在在我的 webconfig.java 中有
@Bean
public Jaxb2Marshaller jaxb2Marshaller() throws SAXException {
org.springframework.core.io.Resource schema = new ClassPathResource("schemas/person-schema.xsd");
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(new Class[]{Person.class});
marshaller.setSchema(schema);
return marshaller;
}
我知道我在我的 java 配置中遗漏了很多东西,我是 java 配置的新手,找不到很多关于如何做到这一点的文档。
任何帮助将不胜感激!
【问题讨论】:
标签: java xml spring spring-mvc jboss