Web services Servlet可以在eclipse中工作,但不能在ApacheTomcat中工作。无法推断基本url…API位于API网关后面
请提前帮助并感谢您。在过去的3天里,我一直在stackoverflow和其他地方研究这个问题。我需要为我的web应用程序有2个URL。它在eclipse中工作,但部署到ApacheTomcat(8.5.16)时不工作。SpringBootVersion2.0.9,SpringVersion5.0.13。 web服务方法不起作用,swagger不断弹出消息:“无法推断基本url。这在使用动态servlet注册或API位于API网关后面时很常见”。这是一个没有如下所示的servlet注册的工作应用程序Web services Servlet可以在eclipse中工作,但不能在ApacheTomcat中工作。无法推断基本url…API位于API网关后面,web-services,servlets,Web Services,Servlets,请提前帮助并感谢您。在过去的3天里,我一直在stackoverflow和其他地方研究这个问题。我需要为我的web应用程序有2个URL。它在eclipse中工作,但部署到ApacheTomcat(8.5.16)时不工作。SpringBootVersion2.0.9,SpringVersion5.0.13。 web服务方法不起作用,swagger不断弹出消息:“无法推断基本url。这在使用动态servlet注册或API位于API网关后面时很常见”。这是一个没有如下所示的servlet注册的工作应用程
public class MyWsApplication extends SpringBootServletInitializer {
// other configurations here
// servlet registration below
@Bean
public DispatcherServlet dispatcherServlet() {
return new DispatcherServlet();
}
@Bean
public ServletRegistrationBean<DispatcherServlet> servletRegistration() {
String url1 = "/web-services-url1/*";
String url2 = "/services_url2/*";
ServletRegistrationBean<DispatcherServlet> registration = new ServletRegistrationBean<>(dispatcherServlet(),
url1, url2);
Map<String, String> params = new HashMap<>();
params.put("contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");
registration.setInitParameters(params);
return registration;
}
}
公共类MyWsApplication扩展了SpringBootServletilizer{
//这里还有其他配置
//下面是servlet注册
@豆子
公共DispatcherServlet DispatcherServlet(){
返回新的DispatcherServlet();
}
@豆子
公共ServletRegistrationBean servletRegistration(){
字符串url1=“/web-services-url1/*”;
字符串url2=“/services_url2/*”;
ServletRegistrationBean registration=新的ServletRegistrationBean(dispatcherServlet(),
url1、url2);
Map params=新的HashMap();
put(“contextClass”,“org.springframework.web.context.support.AnnotationConfigWebApplicationContext”);
registration.setInitParameters(params);
申报登记;
}
}
感谢所有阅读我的问题的人。我通过在tomcat中定义2个应用程序上下文解决了这个问题。添加url不需要所有这些java代码。解决方案: