Shu*_*Rai 7 java swagger-ui spring-boot swagger-2.0
我在 Spring Boot 中面临 Swagger 集成问题。查看代码和错误片段。
------------------POM--------------------
<properties>
<java.version>1.8</java.version>
<swagger.version>2.9.2</swagger.version>
</properties>
<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>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>${swagger.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
-----------------应用类--------------
@SpringBootApplication
@EnableSwagger2
public class ProducerApplication {
public static void main(String[] args) {
SpringApplication.run(ServletPocProducerApplication.class, args);
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
org.springframework.context.ApplicationContextException: Failed to start bean
'documentationPluginsBootstrapper'; nested exception is
java.lang.NullPointerException: Cannot invoke
"org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.toString()"
because the return value of
"springfox.documentation.spi.service.contexts.Orderings.patternsCondition(springfox.docume
ntation.RequestHandler)" is null
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.3.13.jar:5.3.13]
Run Code Online (Sandbox Code Playgroud)
我该如何解决??
小智 21
我通过在 application.properties 中添加“spring.mvc.pathmatch.matching-strategy=ant-path-matcher”解决了这个问题。
小智 10
很长一段时间我一直试图解决这个问题,解决方案是:
a) 将其添加到 application.properties:
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Run Code Online (Sandbox Code Playgroud)
b) 将其添加到 application.yaml(或 application.yml):
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21198 次 |
| 最近记录: |