SpringBoot 集成Swagger后提通過http://localhost:8001/swagger-ui.html#/訪問得不到頁面


SpringBoot 集成Swagger后提通過http://localhost:8001/swagger-ui.html#/訪問得不到頁面:

spring boot  集成 swagger2步驟:

1 maven依賴

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

2:配置類

@EnableSwagger2
@EnableWebMvc
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.controller")) // 注意修改此處的包名
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口列表 v1.1.0") // 任意,請稍微規范點
                .description("接口測試") // 任意,請稍微規范點
                .termsOfServiceUrl("http://localhost:8080/項目名稱/swagger-ui.html") // 將“url”換成自己的ip:port
                .contact("ccccc") // 無所謂(這里是作者的別稱)
                .version("1.1.0")
                .build();
    }
}

3 網上很多教程做到這里,就完成了,但是我發布時候找不到,所以多加了一個配置

package cn.cetc.dealnotice.config;//注意:這是自己的包名!!!!
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Override
   public  void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}

————————————————
版權聲明:本文為CSDN博主「南風一去不復返」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:springboot 集成swagger2 找不到頁面問題

其它鏈接:

1、解決SpringBoot2.0集成Swagger2訪問404的問題

2、springboot 集成swagger2 404 無法訪問

3、請問個springboot整合swagger2頁面無法顯示api信息的問題

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM