Spring3, JAXB2, Java6, NamespacePrefixMapper questions

I built a simple Spring3, Hibernate3 / (JPA2), a RESTful service hosted on Tomcat6 that uses JAXB2 to marshal the results. (It uses annotated pojos.) I needed to use specific namespace prefixes, so I wrote a custom com.sun.xml.bind.marshaller.NamespacePrefixMapper. I turned on the JAXB2 RI banks with my application and everything worked fine.

Then someone said that great, we need to place it in WebLogic 11g (10.3.3) too. No problem, I created special weblogic deployment descriptors to prefer application banks, renamed my persistence.xml and wrapped WAR in EAR with JPA2 banks. It worked perfectly, almost.

Unfortunately, our WebLogic server launches a custom security scope that also uses JAXB and causes conflicts with my application. So I dropped JAXB banks from the application, and it works great in WebLogic. Of course, it no longer works under Tomcat unless I add JAXB to Tomcat. I would like to avoid this.

So, my questions ... I have read quite a few stackoverflow posts that contain a lot of opinions / disagreements regarding the use of the solar "internal" JAXB2 implementation and RI packaging with your application. Is there still no clean solution to this problem? Does my stack support another way to create my own namespace prefixes without including JAXB2 RI? Can I safely use Java6 "internal" JAXB NamespacePrefixMapper, or will it come and go with different versions of Java? Does Spring3 offer another solution? What is the true history of Java6 JAXB2 implementation? Is it for internal use only by Sun (Oracle)?

Thank.

+3
source share
2 answers

, , http://www.func.nl/community/knowledgebase/customize-namespace-prefix-when-marshalling-jaxb.

. , .

, JAXB XMLStreamWriter , , .

XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(writer);
xmlStreamWriter.setPrefix("func", "http://www.func.nl");

JAXBContext context = JAXBContext.newInstance(object.getClass());
Marshaller marshaller = context.createMarshaller();

marshaller.marshal(object, xmlStreamWriter);

, JAXB , XMLStreamWriter , , , , .

: , , , , , .

0

Source: https://habr.com/ru/post/1783515/


All Articles