访问 http://localhost:port{context-path}/swagger-ui.html
如果访问成功则不需要继续下面的配置,如果访问失败出现404报错,则进行下面的配置

配置好了但是访问确实404。究其原因是MVC没有找到swagger-ui包中的swagger-ui.html文件

加入配置文件

package io.github.talelin.latticy.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}

原理就是帮助MVC找到 swagger-ui.html 及其 CSS,JS 对应的文件

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐