spring - Spring Boot 2.1.3.RELEASE,我想要 swagger-ui.html 作为主页/欢迎页面并处理 ROOT 上下文 (/)
问题描述
我在http://localhost:8448/portalapi/swagger-ui.html有 spring boot 2 和 swagger API 页面。但我想映射http://localhost:8448/和http://localhost:8448/portalapi/将请求转发到http://localhost:8448/portalapi/swagger-ui.html。但它不起作用。它给出 HTTP 状态 404 - 未找到(tomcat 默认响应)。非常感谢任何帮助或指针。
应用程序属性
##
# tomcat server port
server.port=8448
#server.address=0.0.0.0
server.servlet.contextPath=/portalapi/
这是一个用于转发上下文的 webconfig 类:
@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");
}
}
解决方案
将下面的部分从:
@Configurable
@Component
public class WebConfig implements WebMvcConfigurer {
至:
@Configuration
public class WebConfig implements WebMvcConfigurer {
推荐阅读
- awk - 无法打开管道太多打开的文件
- excel - Excel VBA 将大于更改为小于会导致运行时错误 1004
- android - 锁屏触发不同activity的应用生命周期事件
- vba - 如何在每封电子邮件的开头添加文本?
- c++ - 如何在 Box2D 和 SFML 中设置固定的绘图速度和世界步数?
- ios - 我想对视频应用 CIFilter 并保存该过滤器应用的视频。[导出耗时太长]
- windows - Windows 服务器容器中的 Unix 命令 - Docker Windows
- sql - PostgreSQL:给定特定时间间隔的一周中每一天的记录计数
- xaml - 如何通过 Tapped Event Handler 传递绑定属性?
- php - 如何以这种并排模式排列数字?