gpt4 book ai didi

java - 在 Spring WebService 中从 WSDL 而不是 XSD 公开 Web 服务

转载 作者:行者123 更新时间:2023-12-04 23:05:25 26 4
gpt4 key购买 nike

在我们的项目中,我们使用了 Spring WebService。配置文件如下:

@EnableWs
@Configuration
public class WebServiceConfiguration extends WsConfigurerAdapter {
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
validatingInterceptor.setValidateRequest(true);
validatingInterceptor.setValidateResponse(true);
validatingInterceptor.setXsdSchema(customerSchema());
interceptors.add(validatingInterceptor);
}

@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/abc/ws/*");
}

@Bean(name = "someInterface")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema priceListSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("SomePortType");
wsdl11Definition.setLocationUri("/abc/ws/someInterface");
wsdl11Definition.setTargetNamespace("someNamespace");
wsdl11Definition.setSchema(priceListSchema);
return wsdl11Definition;
}

@Bean
public XsdSchema customerSchema() {
return new SimpleXsdSchema(new ClassPathResource("SomeXsd.xsd"));
}
}

wsdl 的 XSD 文件是我们保存在类路径中的 SomeXsd.xsd。但是我想知道我是否有将要公开的wsdl文件而不是通过这种方式生成wsdl。我们如何公开已经存在的 wsdl?

最佳答案

您是否尝试删除以下内容

   @Bean(name = "someInterface")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema priceListSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("SomePortType");
wsdl11Definition.setLocationUri("/abc/ws/someInterface");
wsdl11Definition.setTargetNamespace("someNamespace");
wsdl11Definition.setSchema(priceListSchema);
return wsdl11Definition;
}

并添加这个

 @Bean
public WsdlDefinition myWsdl() {
return new SimpleWsdl11Definition(new ClassPathResource("/myWsdl.wsdl"));
}

您仍然需要 validator 的 xsd。您可能还需要更多配置

关于java - 在 Spring WebService 中从 WSDL 而不是 XSD 公开 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43633554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com