Jaxb2Marshaller для нескольких пакетов с одинаковыми классамиJAVA

Программисты JAVA общаются здесь
Anonymous
Jaxb2Marshaller для нескольких пакетов с одинаковыми классами

Сообщение Anonymous »

У меня есть 2 схемы xsd, и я сгенерировал из них классы Java следующим образом:

Код: Выделить всё

org.apache.cxf
cxf-xjc-plugin


generate-sources
generate-sources

xsdtojava




${basedir}/src/main/resources/xsd/schema/1.xsd
${basedir}/src/main/resources/xsd/binding/1.xjb
foo.bar.1


${basedir}/src/main/resources/xsd/schema/2.xsd
${basedir}/src/main/resources/xsd/binding/2.xjb
foo.bar.2






Эти схемы имеют одинаковые классы, поэтому я отсортировал их по разным пакетам.
Я пытаюсь создать Jaxb2Marshaller для этих пакетов следующим образом:

Код: Выделить всё

@Bean
public Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();

marshaller.setPackagesToScan("foo.bar.1","foo.bar.2");

marshaller.setMarshallerProperties(new HashMap() {{
put(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true);
}});

return marshaller;
}
но получил следующее исключение

Код: Выделить всё

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'jaxb2Marshaller' defined in class path resource: Invocation of init method failed; nested exception is
org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is
javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated:
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 51 counts of IllegalAnnotationExceptions.
The element name {}Initial has more than one mapping.
Я думаю, что мне следует создать отдельный маршаллер для каждого пакета, но может быть существует решение, как сделать это с одним маршаллером.

Подробнее здесь: https://stackoverflow.com/questions/514 ... me-classes

Вернуться в «JAVA»