2016-08-16 101 views
1

其實我在春天很新,而且由於某些要求,我正在使用spring-integration,我已經做了很少的JAXB類來將數據轉換成XML並且必須通過webservices發送它,但是作爲迴應,我將XML帶回了一些新元素,我想知道如何使用我製作的相同JAXB類來解組新的XML?使用JAXB解編XML

回答

1

我使用下面的成分來做到這一點(Java配置):

@Bean 
    public Jaxb2Marshaller jaxb2Marshaller() throws Exception { 
     Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 
     /* Packages with root elements (@XmlRootElement). Your JAXB classes */  
     marshaller.setContextPaths("..."); 
     return marshaller; 
    } 

    @Bean 
    @ServiceActivator(inputChannel = "toWebServiceChannel") 
    public MessageHandler wsGateway() throws Exception {      
     ConfigWebServiceURLProvider provider = new ConfigWebServiceURLProvider(isHttps, host, port, endpoint); 
     /* marshaller and unmarshaller could be the same */ 
     MarshallingWebServiceOutboundGateway gw = new MarshallingWebServiceOutboundGateway(url, jaxb2Marshaller(), jaxb2Marshaller()); 
     gw.setOutputChannelName("fromWebServiceChannel"); 
     return gw; 
    }