我使用本指南创建了一个简单的 spring-boot SOAP 网络服务:
https://spring.io/guides/gs/producing-web-service/
我正在将它部署到云服务,但在它前面会有一个 API 管理层。
我希望 WSDL 能够使用 API 管理层的 URL。 (基本上对地址进行硬编码。)
我尝试了两种方法:
@Bean(name = "countries")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("CountriesPort");
wsdl11Definition.setLocationUri("http://example.com/ws");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchema(countriesSchema);
return wsdl11Definition;
}
@Bean(name = "countries")
public SimpleWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("countries.wsdl")); //this WSDL was edited to have the path I want
return wsdl11Definition;
}
我正在用 Maven 构建。在这两种情况下,应用程序托管的 WSDL 用它运行的服务器替换主机名,例如http://localhost:8080/然后使用 URI 的其余部分。
<wsdl:service name="CountriesPortService">
<wsdl:port binding="tns:CountriesPortSoap11" name="CountriesPortSoap11">
<soap:address location="http://localhost:8080/ws"/>
</wsdl:port>
</wsdl:service>
如何设置/覆盖主机名部分
最佳答案
我认为您正在使用 setTransformWsdlLocations(true) 在 messageDispatcherServlet Web 服务配置类的方法。此设置将根据它运行的环境转换 URL。
删除此行,以便它将采用默认设置 fals 并且不会覆盖。
关于spring-boot - 覆盖 WSDL 中的整个地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48793251/