我试图使用SpringWS和Spring Boot公开2个不同的静态WSDL端点。
我遇到的问题是声明两个SimpleWsdl11Definition bean并且只暴露了一个。
这些是我的配置文件:
@EnableWs
@Configuration
public class AWSConfig extends WsConfigurerAdapter
{
@Bean
public ServletRegistrationBean aMessageDispatcherServlet(ApplicationContext applicationContext)
{
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "Av1/*");
}
@Bean(name = "AV1")
public SimpleWsdl11Definition simpleWsdl11Definition()
{
SimpleWsdl11Definition simpleWsdl11Definition = new SimpleWsdl11Definition();
simpleWsdl11Definition.setWsdl(new ClassPathResource("wsdl/AV1.wsdl"));
return simpleWsdl11Definition;
}
@Bean(name = "ASchema")
public XsdSchema aSchema()
{
return new SimpleXsdSchema(new ClassPathResource("xsd/A.xsd"));
}
}
和
@EnableWs
@Configuration
public class BWSConfig
{
@Bean
public ServletRegistrationBean bMessageDispatcherServlet(ApplicationContext applicationContext)
{
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "Bv1/*");
}
@Bean(name = "BV1")
public SimpleWsdl11Definition simpleWsdl11Definition()
{
SimpleWsdl11Definition simpleWsdl11Definition = new SimpleWsdl11Definition();
simpleWsdl11Definition.setWsdl(wsdl/BV1.wsdl"));
return simpleWsdl11Definition;
}
@Bean(name = "bSchema")
public XsdSchema bSchema()
{
return new SimpleXsdSchema(new ClassPathResource("xsd/BV1.xsd"));
}
}
只能访问AV1.wsdl。谁能告诉我我错过了什么...
答案 0 :(得分:1)
在bean定义下创建一个名为MessageDispatcherServlet的方法,其中包含一个重写的getWsdlDefinition方法。如果满足url条件,原始代码中的此方法将选择wsdl以从弹簧启动的WsdlDefinitions列表中公开。下面的覆盖使得可以选择正确的,而不是弹簧的模糊解决方案。手动将URL与wsdl定义配对。
@Bean(name = "servlet-a")
public ServletRegistrationBean messageDispatcherServletA(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
public ServletRegistrationBean messageDispatcherServletA(
ApplicationContext applicationContext,
@Qualifier("A") final Wsdl11Definition a) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet(){
private static final long serialVersionUID = 8547901522243924975L;
@Override
protected WsdlDefinition getWsdlDefinition(HttpServletRequest request) {
if (yourMethodCheckingForRightExposeUrl(request)) {
return a;
}
else {
return null;
}
}
};
servlet.setApplicationContext(applicationContext);
servlet.setMessageReceiverBeanName("yourSpecificReceiverBeanName");
ServletRegistrationBean bean = new ServletRegistrationBean(servlet, "/ws/your-endpoint/*"); // star needed to allow any urls
bean.setName("servlet-a");
return bean;
}
}
WsdlDefininition参数可以具有合格名称' BV1'在你的例子中。