2

I am using swagger to document my spring boot rest application Using

  • spring-boot-starter-web
  • spring-boot-starter-data-rest
  • springfox-swagger2 2.9.2
  • springfox-swagger 2.9.2

Code is building fine but when I run it it is throwing error below

org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration 

$EnableWebMvcConfiguration.class]:
 Unsatisfied dependency expressed through method 'requestMappingHandlerMapping' parameter 1;
nested exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration

$EnableWebMvcConfiguration.class]:
 Bean instantiation via factory method failed;
 nested exception is org.springframework.beans.BeanInstantiationException:
 Failed to instantiate [org.springframework.format.support.FormattingConversionService]: 
Factory method 'mvcConversionService' threw exception; 
nested exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'jsonSchemaConverter' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]:
     Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
 Failed to instantiate [org.springframework.data.rest.webmvc.json.PersistentEntityToJsonSchemaConverter]:
     Factory method 'jsonSchemaConverter' threw exception;
nested exception is org.springframework.beans.factory.BeanCreationException: 
     Error creating bean with name 'defaultConversionService' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]:
     Bean instantiation via factory method failed;  
nested exception is org.springframework.beans.BeanInstantiationException: 
     Failed to instantiate [org.springframework.format.support.DefaultFormattingConversionService]:
     Factory method 'defaultConversionService' threw exception; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
     Error creating bean with name 'repositoryInvokerFactory' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]:
     Bean instantiation via factory method failed;

nested exception is org.springframework.beans.BeanInstantiationException:
 nested exception is org.springframework.beans.BeanInstantiationException:
     Failed to instantiate [org.springframework.data.repository.support.RepositoryInvokerFactory]:
     Factory method 'repositoryInvokerFactory' threw exception;

nested exception is java.lang.NoSuchMethodError:      org.springframework.plugin.core.PluginRegistry.of(Ljava/util/List;)Lorg/springframework/plugin/core/PluginRegistry;   
vym
  • 21
  • 4

1 Answers1

1

I had the same problem. Here is my fix:

TL/DR:

Springfox uses an outdated version of spring-plugin-core and is incompatible with spring boot 2.2.5. Springfox seems to be no longer maintained; migrate to a different spring-swagger-bridge, such as Springdoc-openapi: https://springdoc.github.io/springdoc-openapi-demos/


Relevant output

nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.data.repository.support.RepositoryInvokerFactory]:
Factory method 'repositoryInvokerFactory' threw exception; nested exception is java.lang.NoSuchMethodError:
'org.springframework.plugin.core.PluginRegistry org.springframework.plugin.core.PluginRegistry.of(java.util.List)'

From NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor:

...a wild guess would be that the last working version of springfox (working for you and us) was compiled with a Spring boot version inferior to 2.2.2. That boot version had a different method signature for getPluginOrDefaultFor (or possibly the method didn't exist at all).


Cause

  • springfox imports version 1.2.0 of the spring-plugin-core. Spring Boot 2.2.5 needs version 2.0.0.RELEASE
  • springfox wins the import lottery; test fails b/c Spring Boot can't find its method.
  • explicitly importing 2.0.0.RELEASE makes springfox die.
  • springfox' latest version is 2.9.2; even the 3.0.0-SNAPSHOT does not fix the issue: https://github.com/springfox/springfox/issues/2932


Solution

Yes I ended up following the links to 'springDoc' and found a quick tutorial. It was super easy to setup all in the pom.xml file. Just one tweak was needed
<!-- org.springdoc for swagger setup  -->
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-core</artifactId>
    <version>1.1.49</version>
    <exclusions>
        <exclusion>
            <groupId>io.github.classgraph</groupId>
            <artifactId>classgraph</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.1.49</version>
</dependency>