I'm in the process of writing a spring web app and want to convert my objects to xml without annotations. I know with xml config you can do this:
<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>
In my webconfig.java right now I have
@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;
}
I know I'm missing a lot in my java config, I'm new to java config and can't find a lot of documentation on how to do this.
Any help would be greatly appreciated!
When there is lack of documentation for a given item in xml config to java config, your best friend is to find the javadocs for the involved classes, in this case:
@Bean javadoc, Jaxb2Marshaler javadoc, JAXBRIContext javadoc, and couldn't find the javadoc for IntroductionsConfigParser and IntroductionsAnnotationReader, maybe an active subscription to red hat is required? not sure about that.
I never used these classes myself, so perhaps there might be an error, but my first attempt would look like this:
Not exactly sure about factory-method right now, so i'll post my 2 possible options:
or