我写了一个简单的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相关的证据更新你的问题? –
其实前两天我们解决了这个问题。我现在正在发布解决方案。尽管现在服务的性能有了很大提高,但每个请求基本上都在一秒之内。 –