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 {