У меня есть проект загрузки spring. У меня есть несколько xsds в моем проекте. Я создал классы, используя maven-jaxb2-plugin. Я использовал этот учебник, чтобы получить пример загрузочного приложения spring.
import org.kaushik.xsds.XOBJECT;
@SpringBootApplication
public class JaxbExample2Application {
public static void main(String[] args) {
//SpringApplication.run(JaxbExample2Application.class, args);
XOBJECT xObject = new XOBJECT('a',1,2);
try {
JAXBContext jc = JAXBContext.newInstance(User.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(xObject, System.out);
} catch (PropertyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Но я беспокоюсь, что мне нужно, чтобы все классы jaxb отображаемой схемы. Также есть что-то в spring, которое я могу использовать, чтобы облегчить задачу. Я просмотрел проект spring OXM, но в нем был настроен контекст приложения в xml. У загрузки spring есть что-то, что я могу использовать из коробки. Любые примеры будут полезны.
Edit
Я попробовал ответ xerx593, и я провел простой тест с использованием основного метода
JaxbHelper jaxbHelper = new JaxbHelper();
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(XOBJECT.class);
jaxbHelper.setMarshaller(marshaller);
XOBJECT xOBJECT= (PurchaseOrder)jaxbHelper.load(new StreamSource(new FileInputStream("src/main/resources/PurchaseOrder.xml")));
System.out.println(xOBJECT.getShipTo().getName());
Все прошло отлично. Теперь мне просто нужно подключить его с помощью загрузки spring.