springfox: Springfox data rest: Failed to start bean 'documentationPluginsBootstrapper'
-
Version: 2.9.2
-
Type: Question.
Hello,
I’ve been using springfox swagger with the normal JPA repositories. I’ve now included a repository which uses spring data rest.
In order to have it show in the swagger ui, I required springfox-data-rest.
I’ve also added @Import(SpringDataRestConfiguration.class) to my swagger configuration class.
Here is the full stacktrace:
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.data.repository.support.Repositories.getRepositoryInformationFor(Ljava/lang/Class;)Lorg/springframework/data/repository/core/RepositoryInformation;
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:184) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:52) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:157) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:121) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:885) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at com.nwidart.techvideo.TechVideoApplication.main(TechVideoApplication.java:16) [classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.3.RELEASE.jar:2.0.3.RELEASE]
Caused by: java.lang.NoSuchMethodError: org.springframework.data.repository.support.Repositories.getRepositoryInformationFor(Ljava/lang/Class;)Lorg/springframework/data/repository/core/RepositoryInformation;
at springfox.documentation.spring.data.rest.EntityServicesProvider.requestHandlers(EntityServicesProvider.java:81) ~[springfox-data-rest-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:138) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper$2.apply(DocumentationPluginsBootstrapper.java:135) ~[springfox-spring-web-2.9.2.jar:null]
at com.google.common.collect.Iterators$8.transform(Iterators.java:794) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.Iterators$5.hasNext(Iterators.java:543) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.ImmutableCollection$Builder.addAll(ImmutableCollection.java:300) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.ImmutableList$Builder.addAll(ImmutableList.java:691) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:275) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.ImmutableList.copyOf(ImmutableList.java:226) ~[guava-jdk5-17.0.jar:na]
at com.google.common.collect.FluentIterable.toList(FluentIterable.java:334) ~[guava-jdk5-17.0.jar:na]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.defaultContextBuilder(DocumentationPluginsBootstrapper.java:111) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.buildContext(DocumentationPluginsBootstrapper.java:96) ~[springfox-spring-web-2.9.2.jar:null]
at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:167) ~[springfox-spring-web-2.9.2.jar:null]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
... 19 common frames omitted
Relevant pom:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>2.9.2</version>
</dependency>
My swagger configuration class:
package com.nwidart.techvideo.config;
import java.time.LocalDate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
@Profile("!tests")
@Import(SpringDataRestConfiguration.class)
public class SwaggerConfiguration {
@Bean
public Docket mainConfig() {
return new Docket(DocumentationType.SWAGGER_2)
.select().apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*"))
.build()
.apiInfo(apiInfo())
.directModelSubstitute(LocalDate.class, String.class)
.genericModelSubstitutes(ResponseEntity.class);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Tech Video")
.description("Manage tech learning sessions")
.version("1.0")
.contact(new Contact("Nicolas Widart", "https://nicolaswidart.com", "n.widart@gmail.com"))
.build();
}
}
I’ve looked through the docs but couldn’t find a lot of information on springfox data rest.
Thanks!
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 10
- Comments: 50 (6 by maintainers)
@simbro I’ve done this:
With:
@EnableSwagger2WebMvc@Import(SpringDataRestConfiguration.class)I recompiled springfox-data-rest 2.9.2 against spring-data-commons 2.1.4, and changed a single line in
EntityContext:return entities.getPersistentEntity(actualDomainType);becomesreturn entities.getPersistentEntity(actualDomainType).orElse(null);Using that,SpringDataRestConfigurationworks like a charm.Since there seems to be no timeline for a 3.x release, I think quite a few people would appreciate a 2.9.3 release with this small fix. I know I would. - Thank you!
Do you still have this issue? I had the same issue, and I found my project had downloaded guava version of 19.0, not 20.0. I figured out which library has dependency for 19.0 guava, and I put exclusion like below. and It works!
I’m currently trying again, and getting the following after adding the
@Import(SpringDataRestConfiguration.class)annotation:Is there anything I missed?
@ke88yun yes in the next few weeks. Sorry I was on a break from OSS, just to help prevent burnout (plus my day job).
Hi, is there an estimated date for the release of version 3 of Springfox? It’s terrible to use a SNAPSHOT version in a productive environment.
Thanks.
Does anyone have a definitive fix for this issue? I’ve tried all the approaches mentioned above (as best as I could follow from the thread) but still having the exact same issue as nWidart.
mine work well
@see official doc
Actually, after this springfox swagger alone works. But not with the
@Import(SpringDataRestConfiguration.class)annotation for spring data rest, just like @evgenruAfter adding the import annotation I have
From this issue (https://github.com/springfox/springfox/issues/2298#issuecomment-410484583) it seems to be a known issue and won’t be fixed until 3.x.
The issue has been resolved.
com.google.collectionsdependency,google-http-client-jackson2from1.22.0to1.23.0,google-api-services-youtube.Thank you for the hints, they managed to point me in the right direction. 👍
Oh I see.
I’ve added this:
Still getting the error however.
Do I need to specifically use version 20 you linked?
(Btw I’m using 2.8.0 on spring boot 2.0.4)
Thanks
Edit: same with version
21.0. I see that guava 20 is a transitive dependency of springfox-swagger though, so it should be at the right version I assume.Even i am facing the same issue with spring boot 2.6.2 and spring-fox-starter 3.0.0
@armando-reyna
Here is one of the Repository class, we have several others which are similar but for different domain entities.
@armando-reyna Thanks, with @EnableSwagger2WebMvc annotation, my code does run with no error, however there is no API document generated for those endpoints implemented by Spring Data Rest. The following is my configuration for io.springfox:springfox-data-rest:3.0.0-SNAPSHOT
and here is my POM.xml file
now work with maven { url ‘http://oss.jfrog.org/artifactory/oss-snapshot-local/’ } compile(‘io.springfox:springfox-data-rest:3.0.0-SNAPSHOT’)
PS: updated repository )