1. 程式人生 > 其它 >SpringBoot 整合Swagger後提通過http://localhost:8001/swagger-ui.html#/訪問得不到頁面

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資訊的問題