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

12,762

This error happens when a piece of code has been compiled with a given method signature, but at runtime, another is found.

This usually happens when there's a difference between the version of a dependency used at compile time, and the dependency that is actually provided to the program at runtime.

We just had this error as well with a colleague, and we fixed it by simply changing the spring boot version to 2.2.2.

Not sure what exactly happened, but given the version is a SNAPSHOT, 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).

Your program sees no difference, because the swagger lib's API didn't change, so it seems like nothing changed and there's suddenly an error. But the actual swagger lib's underlying implementation relies on some method from Spring Boot 2.2.2, which it doesn't find in your setup since Boot's version is 2.1.0, and this generates a conflict between what it expects to find and what it actually does.

Anyway, just upgrading your Boot to 2.2.2 should fix it ; possibly downgrading spring-fox to 2.9.2 if you don't need the webflux module- but it seems you do (didn't get the chance to try, because in our case we do need the springfox webflux dependency)

Share:
12,762

Related videos on Youtube

Mateusz Gebroski
Author by

Mateusz Gebroski

Updated on September 15, 2022

Comments

  • Mateusz Gebroski
    Mateusz Gebroski over 1 year

    Everything was fine, even with Swagger however suddenly after new build project won't compile throwing

    Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor(Ljava/lang/Object;Lorg/springframework/plugin/core/Plugin;)Lorg/springframework/plugin/core/Plugin;
    

    I have tried solution from this link: https://github.com/springfox/springfox/issues/2932 however compilation error still persist.

    I am attaching pom.xml file:

    <?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 https://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.0.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <groupId>com.geborskimateusz.microservices.composite.movie</groupId>
        <artifactId>movie-composite-service</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <name>movie-composite-service</name>
        <description>Demo project for Spring Boot</description>
    
        <properties>
            <java.version>1.8</java.version>
            <swagger.version>3.0.0-SNAPSHOT</swagger.version>
        </properties>
    
    
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-webflux</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.projectreactor</groupId>
                <artifactId>reactor-test</artifactId>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.18.8</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.geborskimateusz</groupId>
                <artifactId>api</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.geborskimateusz</groupId>
                <artifactId>util</artifactId>
                <version>0.0.1-SNAPSHOT</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-engine</artifactId>
                <version>5.1.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger2</artifactId>
                <version>${swagger.version}</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-spring-webflux</artifactId>
                <version>${swagger.version}</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${swagger.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-stream-kafka</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-stream-test-support</artifactId>
                <scope>test</scope>
            </dependency>
    
        </dependencies>
    
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>Greenwich.RELEASE</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
        <repositories>
            <repository>
                <id>jcenter-snapshots</id>
                <name>jcenter</name>
                <url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
            </repository>
        </repositories>
    
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>
    

    Any ideas, is this related to swagger version?

  • Mateusz Gebroski
    Mateusz Gebroski over 4 years
    Thank you Mikado, I had to change Boot to 2.2.2 and then change spring cloud version to Hoxton :)
  • Eric Miller
    Eric Miller about 4 years
    This helped me a lot. Thanks!
  • msmukesh4
    msmukesh4 about 4 years
    Worked for me too @Mikado One question I have, while upgrading the spring boot version from 2.1.2 -> 2.2.2 do I have to make any changes to my existing code
  • Anorgar
    Anorgar almost 4 years
    To be exact, this error is a dependency conflict between Springfox 3+ and Springboot 2+. To solve it, I fixed Springfox dependency to 2.7.0 and it work.