使用 springfox-swagger2 版本 3.0.0-SNAPSHOT 观察错误 "Unable to infer base url"
Observing error "Unable to infer base url" with springfox-swagger2 version 3.0.0-SNAPSHOT
我正在使用 spring-boot 2.1.6.RELEASE
和 springfox-swagger2
版本 3.0.0-SNAPSHOT
。但无法启动 swagger-ui(即 http://localhost:808/swagger-ui.html) or api-docs (i.e http://localhost:8080/v2/api-docs)网址。
相同的配置适用于 springfox-swagger2 version 2.9.2
。唯一的区别是 @EnableSwagger2WebMvc
与 3.0.0-SNAPSHOT
.
相加
错误详情
这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath />
<!-- lookup parent from service -->
</parent>
<groupId>com.mytrainst.train</groupId>
<artifactId>mytransit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mytransit</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
</project>
这是 Swagger 配置
package com.mytrainst.train.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/");
}
}
控制器接口
package com.mytrainst.train.controller;
import com.mytrainst.train.domain.Train;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/trains", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public interface ITrainController {
@GetMapping("/name/{name}")
Train findByName(@PathVariable final String name);
}
控制器实现
package com.mytrainst.train.controller;
import com.mytrainst.train.domain.Train;
import com.mytrainst.train.service.ITrainService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
@Component
@AllArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class TrainController implements ITrainController {
private ITrainService trainService;
@Override
public Train findByName(@PathVariable final String name) {
log.info(":: Request received: {} ", name);
return trainService.findByName(name);
}
}
Spring 引导应用程序
package com.mytrainst.train;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
和springwebframework日志和TRACE
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
11:31:36.785 [main] DEBUG o.s.w.c.ContextLoader - Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
11:31:36.785 [main] INFO o.s.w.c.ContextLoader - Root WebApplicationContext: initialization completed in 1235 ms
11:31:38.159 [main] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped [/**/favicon.ico] onto ResourceHttpRequestHandler [class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/], class path resource []]
11:31:38.159 [main] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Patterns [/**/favicon.ico] in 'faviconHandlerMapping'
11:31:38.269 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerAdapter - ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
11:31:38.300 [main] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping -
c.m.t.c.TrainController:
{GET /trains/name/{name}, produces [application/json;charset=UTF-8]}: findByName(String)
11:31:38.315 [main] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping -
o.s.b.a.w.s.e.BasicErrorController:
{ /error}: error(HttpServletRequest)
{ /error, produces [text/html]}: errorHtml(HttpServletRequest,HttpServletResponse)
11:31:38.315 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - 3 mappings in 'requestMappingHandlerMapping'
11:31:38.315 [main] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Detected 0 mappings in 'beanNameHandlerMapping'
11:31:38.315 [main] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped [/webjars/**] onto ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]
11:31:38.315 [main] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped [/**] onto ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
11:31:38.315 [main] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
11:31:38.331 [main] DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
11:31:47.329 [http-nio-8080-exec-1] INFO o.s.w.s.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
11:31:47.329 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - Detected org.springframework.web.multipart.support.StandardServletMultipartResolver@4837f97e
11:31:47.329 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No LocaleResolver 'localeResolver': using default [AcceptHeaderLocaleResolver]
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No ThemeResolver 'themeResolver': using default [FixedThemeResolver]
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No RequestToViewNameTranslator 'viewNameTranslator': using default [DefaultRequestToViewNameTranslator]
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No FlashMapManager 'flashMapManager': using default [SessionFlashMapManager]
11:31:47.345 [http-nio-8080-exec-1] DEBUG o.s.w.s.DispatcherServlet - enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
11:31:47.345 [http-nio-8080-exec-1] INFO o.s.w.s.DispatcherServlet - Completed initialization in 16 ms
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-ui.html", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.360 [http-nio-8080-exec-1] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.376 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.376 [http-nio-8080-exec-1] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.454 [http-nio-8080-exec-2] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/springfox.css?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-2] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-3] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/swagger-ui.css?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-2] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-5] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/swagger-ui-standalone-preset.js?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-4] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/swagger-ui-bundle.js?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-6] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/springfox.js?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-3] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-3] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-4] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-6] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-5] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-4] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-6] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-5] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.469 [http-nio-8080-exec-2] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.469 [http-nio-8080-exec-2] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.469 [http-nio-8080-exec-6] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.469 [http-nio-8080-exec-6] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.469 [http-nio-8080-exec-3] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.469 [http-nio-8080-exec-3] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.469 [http-nio-8080-exec-5] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.485 [http-nio-8080-exec-5] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.501 [http-nio-8080-exec-4] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.501 [http-nio-8080-exec-4] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.719 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-resources/configuration/ui", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.719 [http-nio-8080-exec-7] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.719 [http-nio-8080-exec-7] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found
11:31:47.719 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.719 [http-nio-8080-exec-7] DEBUG o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND, headers={}
11:31:47.735 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.735 [http-nio-8080-exec-7] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
11:31:47.735 [http-nio-8080-exec-7] TRACE o.s.w.s.m.m.a.ServletInvocableHandlerMethod - Arguments: [org.apache.catalina.core.ApplicationHttpRequest@6c5d58b]
11:31:47.751 [http-nio-8080-exec-7] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
11:31:47.751 [http-nio-8080-exec-7] TRACE o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [{timestamp=Thu Jul 04 11:31:47 EDT 2019, status=404, error=Not Found, message=No message available, path=/swagger-resources/configuration/ui}]
11:31:47.782 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.782 [http-nio-8080-exec-7] DEBUG o.s.w.s.DispatcherServlet - Exiting from "ERROR" dispatch, status 404, headers={masked}
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/favicon-32x32.png?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.782 [http-nio-8080-exec-8] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-resources/configuration/security", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND, headers={}
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.m.m.a.ServletInvocableHandlerMethod - Arguments: [org.apache.catalina.core.ApplicationHttpRequest@21a5053e]
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [{timestamp=Thu Jul 04 11:31:47 EDT 2019, status=404, error=Not Found, message=No message available, path=/swagger-resources/configuration/security}]
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.DispatcherServlet - Exiting from "ERROR" dispatch, status 404, headers={masked}
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-resources", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND, headers={}
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.m.m.a.ServletInvocableHandlerMethod - Arguments: [org.apache.catalina.core.ApplicationHttpRequest@2e4ca218]
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [{timestamp=Thu Jul 04 11:31:47 EDT 2019, status=404, error=Not Found, message=No message available, path=/swagger-resources}]
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.DispatcherServlet - Exiting from "ERROR" dispatch, status 404, headers={masked}
我不确定在将 springfox-swagger2 与版本 3.0.0-SNAPSHOT 一起使用时我错过了什么。我根本没有启用任何安全性。我想使用普通香草 spring-web 和 swagger。非常感谢解决此问题的任何指示。
据我所知,springboot 2 不适用于 swagger 2.9。
请参考this 话题
将缺少的依赖项添加到 pom.xml
后问题已解决
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webmvc</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
我正在使用 spring-boot 2.1.6.RELEASE
和 springfox-swagger2
版本 3.0.0-SNAPSHOT
。但无法启动 swagger-ui(即 http://localhost:808/swagger-ui.html) or api-docs (i.e http://localhost:8080/v2/api-docs)网址。
相同的配置适用于 springfox-swagger2 version 2.9.2
。唯一的区别是 @EnableSwagger2WebMvc
与 3.0.0-SNAPSHOT
.
错误详情
这是我的 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath />
<!-- lookup parent from service -->
</parent>
<groupId>com.mytrainst.train</groupId>
<artifactId>mytransit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>mytransit</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>spring-mock-mvc</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
</project>
这是 Swagger 配置
package com.mytrainst.train.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
@Configuration
@EnableSwagger2WebMvc
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.pathMapping("/");
}
}
控制器接口
package com.mytrainst.train.controller;
import com.mytrainst.train.domain.Train;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "/trains", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public interface ITrainController {
@GetMapping("/name/{name}")
Train findByName(@PathVariable final String name);
}
控制器实现
package com.mytrainst.train.controller;
import com.mytrainst.train.domain.Train;
import com.mytrainst.train.service.ITrainService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
@Component
@AllArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class TrainController implements ITrainController {
private ITrainService trainService;
@Override
public Train findByName(@PathVariable final String name) {
log.info(":: Request received: {} ", name);
return trainService.findByName(name);
}
}
Spring 引导应用程序
package com.mytrainst.train;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
和springwebframework日志和TRACE
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
11:31:36.785 [main] DEBUG o.s.w.c.ContextLoader - Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
11:31:36.785 [main] INFO o.s.w.c.ContextLoader - Root WebApplicationContext: initialization completed in 1235 ms
11:31:38.159 [main] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped [/**/favicon.ico] onto ResourceHttpRequestHandler [class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/], class path resource []]
11:31:38.159 [main] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Patterns [/**/favicon.ico] in 'faviconHandlerMapping'
11:31:38.269 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerAdapter - ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
11:31:38.300 [main] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping -
c.m.t.c.TrainController:
{GET /trains/name/{name}, produces [application/json;charset=UTF-8]}: findByName(String)
11:31:38.315 [main] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping -
o.s.b.a.w.s.e.BasicErrorController:
{ /error}: error(HttpServletRequest)
{ /error, produces [text/html]}: errorHtml(HttpServletRequest,HttpServletResponse)
11:31:38.315 [main] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - 3 mappings in 'requestMappingHandlerMapping'
11:31:38.315 [main] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Detected 0 mappings in 'beanNameHandlerMapping'
11:31:38.315 [main] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped [/webjars/**] onto ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]
11:31:38.315 [main] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped [/**] onto ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
11:31:38.315 [main] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
11:31:38.331 [main] DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
11:31:47.329 [http-nio-8080-exec-1] INFO o.s.w.s.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
11:31:47.329 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - Detected org.springframework.web.multipart.support.StandardServletMultipartResolver@4837f97e
11:31:47.329 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No LocaleResolver 'localeResolver': using default [AcceptHeaderLocaleResolver]
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No ThemeResolver 'themeResolver': using default [FixedThemeResolver]
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No RequestToViewNameTranslator 'viewNameTranslator': using default [DefaultRequestToViewNameTranslator]
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No FlashMapManager 'flashMapManager': using default [SessionFlashMapManager]
11:31:47.345 [http-nio-8080-exec-1] DEBUG o.s.w.s.DispatcherServlet - enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
11:31:47.345 [http-nio-8080-exec-1] INFO o.s.w.s.DispatcherServlet - Completed initialization in 16 ms
11:31:47.345 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-ui.html", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.360 [http-nio-8080-exec-1] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.376 [http-nio-8080-exec-1] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.376 [http-nio-8080-exec-1] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.454 [http-nio-8080-exec-2] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/springfox.css?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-2] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-3] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/swagger-ui.css?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-2] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-5] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/swagger-ui-standalone-preset.js?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-4] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/swagger-ui-bundle.js?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-6] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/springfox.js?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.454 [http-nio-8080-exec-3] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-3] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-4] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-6] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-5] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.454 [http-nio-8080-exec-4] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-6] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.454 [http-nio-8080-exec-5] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.469 [http-nio-8080-exec-2] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.469 [http-nio-8080-exec-2] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.469 [http-nio-8080-exec-6] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.469 [http-nio-8080-exec-6] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.469 [http-nio-8080-exec-3] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.469 [http-nio-8080-exec-3] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.469 [http-nio-8080-exec-5] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.485 [http-nio-8080-exec-5] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.501 [http-nio-8080-exec-4] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.501 [http-nio-8080-exec-4] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.719 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-resources/configuration/ui", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.719 [http-nio-8080-exec-7] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.719 [http-nio-8080-exec-7] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found
11:31:47.719 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.719 [http-nio-8080-exec-7] DEBUG o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND, headers={}
11:31:47.735 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.735 [http-nio-8080-exec-7] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
11:31:47.735 [http-nio-8080-exec-7] TRACE o.s.w.s.m.m.a.ServletInvocableHandlerMethod - Arguments: [org.apache.catalina.core.ApplicationHttpRequest@6c5d58b]
11:31:47.751 [http-nio-8080-exec-7] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
11:31:47.751 [http-nio-8080-exec-7] TRACE o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [{timestamp=Thu Jul 04 11:31:47 EDT 2019, status=404, error=Not Found, message=No message available, path=/swagger-resources/configuration/ui}]
11:31:47.782 [http-nio-8080-exec-7] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.782 [http-nio-8080-exec-7] DEBUG o.s.w.s.DispatcherServlet - Exiting from "ERROR" dispatch, status 404, headers={masked}
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.DispatcherServlet - GET "/webjars/springfox-swagger-ui/favicon-32x32.png?v=3.0.0-SNAPSHOT", parameters={masked}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns [/webjars/**, /**]
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]] and 4 interceptors
11:31:47.782 [http-nio-8080-exec-8] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.782 [http-nio-8080-exec-8] DEBUG o.s.w.s.DispatcherServlet - Completed 200 OK, headers={masked}
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-resources/configuration/security", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND, headers={}
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.m.m.a.ServletInvocableHandlerMethod - Arguments: [org.apache.catalina.core.ApplicationHttpRequest@21a5053e]
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [{timestamp=Thu Jul 04 11:31:47 EDT 2019, status=404, error=Not Found, message=No message available, path=/swagger-resources/configuration/security}]
11:31:47.798 [http-nio-8080-exec-9] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.798 [http-nio-8080-exec-9] DEBUG o.s.w.s.DispatcherServlet - Exiting from "ERROR" dispatch, status 404, headers={masked}
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - GET "/swagger-resources", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.h.SimpleUrlHandlerMapping - Mapped to HandlerExecutionChain with [ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]] and 4 interceptors
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND, headers={}
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - "ERROR" dispatch for GET "/error", parameters={}, headers={masked} in DispatcherServlet 'dispatcherServlet'
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.m.m.a.ServletInvocableHandlerMethod - Arguments: [org.apache.catalina.core.ApplicationHttpRequest@2e4ca218]
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [application/json] and supported [application/json, application/*+json, application/json, application/*+json]
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [{timestamp=Thu Jul 04 11:31:47 EDT 2019, status=404, error=Not Found, message=No message available, path=/swagger-resources}]
11:31:47.813 [http-nio-8080-exec-10] TRACE o.s.w.s.DispatcherServlet - No view rendering, null ModelAndView returned.
11:31:47.813 [http-nio-8080-exec-10] DEBUG o.s.w.s.DispatcherServlet - Exiting from "ERROR" dispatch, status 404, headers={masked}
我不确定在将 springfox-swagger2 与版本 3.0.0-SNAPSHOT 一起使用时我错过了什么。我根本没有启用任何安全性。我想使用普通香草 spring-web 和 swagger。非常感谢解决此问题的任何指示。
据我所知,springboot 2 不适用于 swagger 2.9。 请参考this 话题
将缺少的依赖项添加到 pom.xml
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-spring-webmvc</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>