我寫了一個簡單的SOAP端點基本上按照這裏找到春天教程:https://spring.io/guides/gs/producing-web-service/春天SOAP端點 - 緩存的JAXBContext
下面是用於攔截請求類(假設庫對象注入):
@Endpoint
public class SampleEndpoint {
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "SampleRequest")
public
@ResponsePayload
JAXBElement<SampleResponseType> sampleQuery(
@RequestPayload JAXBElement<SampleRequestType> request) {
ObjectFactory factory = new ObjectFactory();
SampleResponseType response = repository.query(request.getValue());
JAXBElement<SampleResponseType> jaxbResponse = factory.createSampleResponse(response);
return jaxbResponse;
}
}
服務正常運行。我遇到的一個問題是性能問題,特別是在反編組時。平均來說,將對象解組爲XML響應需要花費幾秒鐘。有沒有一種方法來緩存/注入JaxbContext Spring在這個過程中用來改善這個時間?
下面是我用於此端點的Web服務配置文件。我試過交替SAAJ和公理的消息工廠之間卻沒有看到太大的業績變化:
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public SaajSoapMessageFactory soap12MessageFactory() {
SaajSoapMessageFactory factory = new SaajSoapMessageFactory();
factory.setSoapVersion(SoapVersion.SOAP_12);
return factory;
}
@Bean
public AxiomSoapMessageFactory axiomSoapMessageFactory() {
AxiomSoapMessageFactory factory = new AxiomSoapMessageFactory();
factory.setSoapVersion(SoapVersion.SOAP_12);
factory.setPayloadCaching(false);
return factory;
}
@Bean
public ServletRegistrationBean dispatcherServlet(
ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
servlet.setMessageFactoryBeanName("soap12MessageFactory");
return new ServletRegistrationBean(servlet, "/ws/*");
}
@Bean(name = "wsdlname")
public DefaultWsdl11Definition xcpdDefaultXcpdWsdl11Definition(XsdSchema
schema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setCreateSoap11Binding(false);
wsdl11Definition.setCreateSoap12Binding(true);
wsdl11Definition.setPortTypeName("xcpdPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition
.setTargetNamespace("http://somenamespace.org/");
wsdl11Definition.setSchema(schema);
return wsdl11Definition;
}
@Bean
public XsdSchema schema() {
return new SimpleXsdSchema(
new ClassPathResource(
"schema.xsd"));
}
}
的'JAXBContext's是每種類型已經緩存,因此試圖增加額外的緩存添加任何內容。 –
邁克,你能否用你有證據表明性能問題與JAXBContext相關的證據更新你的問題? –
其實前兩天我們解決了這個問題。我現在正在發佈解決方案。儘管現在服務的性能有了很大提高,但每個請求基本上都在一秒之內。 –