首页 > 解决方案 > ServletRegistrationBean 不适用于多个 URL 映射路径

问题描述

我正在开发查看https://howtodoinjava.com/spring-boot/spring-boot-soap-webservice-example/的代码,在下面的 bean 中我想允许对 and 执行请求/*/service/*所以我改为

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

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

/service/*当我们执行url时,下面的配置不起作用。我们如何解决这个问题?

标签: springspring-bootsoapspring-ws

解决方案


映射对我有用。我下载了示例并根据您的问题进行了更改。

我看到了已注册的映射(日志)和加载的 wsdl(浏览器),如屏幕截图所示。

Mapping servlet: 'messageDispatcherServlet' to [/*, /service/*]

Spring Boot 日志、WSDL 启动日志和wsdl Soap 请求响应

肥皂请求响应

不确定什么不适合你。“当我们执行 /service/* url 时,以下配置不起作用。”


推荐阅读