I have spring boot 2 and swagger API page working at http://localhost:8448/portalapi/swagger-ui.html. But I wanted to map http://localhost:8448/ and http://localhost:8448/portalapi/ to forward the request to http://localhost:8448/portalapi/swagger-ui.html. But it is not working. It gives HTTP Status 404 – Not Found (tomcat default response). Any help or pointer is greatly appreciated.
appliacation.properties
##
# tomcat server port
server.port=8448
#server.address=0.0.0.0
server.servlet.contextPath=/portalapi/
This is a webconfig class to context to forward:
@Configurable
@Component
public class WebConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
// forward requests to /admin and /user to their index.html
registry.addViewController("/").setViewName(
"forward:/portalapi/swagger-ui.html");
registry.addViewController("/portalapi/").setViewName(
"forward:/portalapi/swagger-ui.html");
}
}