springboot整合swagger o.s.web.servlet.PageNotFound : No mapping for GET /null/swagger-resources

 springboot 2.1.4整合swagger2.9.2,启动控制台会出现如下问题:

       控制台:

2019-04-24 13:00:45.945  INFO 13548 --- [           main] .d.s.w.r.o.CachingOperationNameGenerator : Generating unique operation named: queryUsingGET_1
2019-04-24 13:00:45.986  INFO 13548 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8888 (http) with context path '/hotal'
2019-04-24 13:00:45.989  INFO 13548 --- [           main] com.jw.hotal.HotalApplication            : Started HotalApplication in 7.59 seconds (JVM running for 8.386)
2019-04-24 13:00:46.216  INFO 13548 --- [nio-8888-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/hotal]  : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-04-24 13:00:46.216  INFO 13548 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-04-24 13:00:46.226  INFO 13548 --- [nio-8888-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 10 ms
2019-04-24 13:00:46.239  INFO 13548 --- [nio-8888-exec-1] a.s.s.m.AbstractValidatingSessionManager : Enabling session validation scheduler...
2019-04-24 13:00:46.263  WARN 13548 --- [nio-8888-exec-1] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources/configuration/ui
2019-04-24 13:00:46.312  WARN 13548 --- [nio-8888-exec-4] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources/configuration/security
2019-04-24 13:00:46.320  WARN 13548 --- [nio-8888-exec-7] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources
2019-04-24 13:00:46.327  WARN 13548 --- [nio-8888-exec-8] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources/configuration/ui
2019-04-24 13:00:46.333  WARN 13548 --- [nio-8888-exec-5] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources/configuration/security
2019-04-24 13:00:46.339  WARN 13548 --- [io-8888-exec-13] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources
2019-04-24 13:00:46.346  WARN 13548 --- [nio-8888-exec-3] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources/configuration/ui
2019-04-24 13:00:46.351  WARN 13548 --- [io-8888-exec-16] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources/configuration/security
2019-04-24 13:00:46.357  WARN 13548 --- [nio-8888-exec-9] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources
2019-04-24 13:00:46.363  WARN 13548 --- [io-8888-exec-10] o.s.web.servlet.PageNotFound             : No mapping for GET /hotal/null/swagger-resources/configuration/ui

pom.xml部分: 

       <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.4.RELEASE</version>
            <relativePath/> 
        </parent>  
 
           ..........
        <swagger.version>2.9.2</swagger.version>

          ..........

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>

原本swagger 配置类: 

package com.jw.hotal.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @auther: lucifer
 * @date: 2019/4/20
 * @description:
 */
@Configuration
@EnableSwagger2
public class Swagger2Config extends WebMvcConfigurationSupport {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xx.xxxx.controller"))
                .paths(PathSelectors.any())
                .build();
    }


    @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/");
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("xxxxx")
                .description("Swagger2构建RESTful APIs")
                .termsOfServiceUrl("http://www.baidu.com/")
                //.contact("")
                .version("1.0")
                .build();
    }
}


 由原来继承WebMvcConfigurationSupport 现需要改成:实现WebMvcConfigurer 

public class Swagger2Config implements WebMvcConfigurer {

 

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值