Issue
Please help and thank you in advance. For the past 3 days, I had been looking into this issue in stackoverflow and elsewhere. I need to have 2 urls for my web application. It works in eclipse but it does not work when deployed to apache-tomcat (8.5.16). SpringBootVersion 2.0.9, SpringVersion 5.0.13. The web-services methods do not work, and swagger keeps popping the message: "Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway". This is a working application without the servlet registration shown below.
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;
}
}
Solution
Thanks to all who read my question. I have solved this by defining 2 application contexts in tomcat. All those java code is not needed for adding an url. Solution: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming
Answered By - user123456789
Answer Checked By - Mildred Charles (JavaFixing Admin)