添加 swagger 配置后应用程序失败
我正在使用 spring boot,我想添加 swagger 配置,问题是在运行应用程序后出现此错误:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [springfox.boot.starter.autoconfigure.OpenApiAutoConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [springfox/documentation/spring/web/SpringfoxWebConfiguration.class] cannot be opened because it does not exist
在我的类中我添加了此方法:
@Configuration
public class SpringFoxConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(input -> true)
.apis(input -> true)
.build()
.apiInfo(apiDetails());
}
private ApiInfo apiDetails() {
return new ApiInfoBuilder()
.title("School Jpa")
.contact(new Contact("Robs","url", "email"))
.description("Crud Jpa sample")
.build();
}
在我的 pom.xml 中我添加了此依赖项:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
我无法理解出了什么问题,我按照在线解决方案要求我添加 @EnableSwagger2WebMv 和 @EnableSwagger2 但我仍然收到错误。 我尝试在 SpringBootApplication 中添加 @EnableSwagger2 ,但收到此错误:
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
I'm using spring boot and I want to add swagger configuration, the problem is after I run the application I get this error:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [springfox.boot.starter.autoconfigure.OpenApiAutoConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [springfox/documentation/spring/web/SpringfoxWebConfiguration.class] cannot be opened because it does not exist
In my class I added this methods:
@Configuration
public class SpringFoxConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.paths(input -> true)
.apis(input -> true)
.build()
.apiInfo(apiDetails());
}
private ApiInfo apiDetails() {
return new ApiInfoBuilder()
.title("School Jpa")
.contact(new Contact("Robs","url", "email"))
.description("Crud Jpa sample")
.build();
}
In my pom.xml I added this dependencies:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
I can't understand what is wrong, I followed online solution asking me to add @EnableSwagger2WebMv and @EnableSwagger2 but I still get errors.
I tried to add @EnableSwagger2 in the SpringBootApplication and I get this error:
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的应用程序正在工作,
我还添加到 application.properties 这个,但我添加这个是因为 spring 版本
,并且我添加了这些依赖项
My application is working that
Also i added to application.properties this, but i added this because of spring version
and i added these dependencies