spring-bootswaggerjersey-2.0

No operations defined in spec! error on swagger UI


I am working on to migrate the version of spring boot. I am using spring boot with jersey. After upgrade the version of spring boot and other dependencies, swagger is not working for me. I did not modified any configuration.

Dependencies in pom:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.10</version>
    </parent>

<dependencyManagement>
        <dependencies>
            <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> 
                <version>Finchley.SR1</version> <type>pom</type> <scope>import</scope> </dependency> -->
            <!-- Jersey -->
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>

<dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-jersey2-jaxrs</artifactId>
            <version>1.6.6</version>
        </dependency>

Swagger configuration:

private void configureSwagger() {
        register(SwaggerSerializers.class);
        register(ApiListingResource.class);

        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setTitle("API documentation");
        beanConfig.setVersion(api.name());
        beanConfig.setSchemes(new String[] {
                "https", "http"
        });
        beanConfig.setBasePath("/api" + api.getPath());

        // ConfigId and ScannerId must also be set as init parameters
        // during servlet configuration
        beanConfig.setConfigId(api.name());
        beanConfig.setScannerId(api.name());
        beanConfig.setUsePathBasedConfig(true);

        beanConfig.setResourcePackage("com.api.v1.priv.resources");
        beanConfig.setPrettyPrint(true);
        beanConfig.setScan(true);
    }

Changes in migration: Spring boot version upgraded from 2.0.5.RELEASE => 2.6.10 swagger-jersey2-jaxrs upgraded from 1.5.18 => 1.6.6

Note - Swagger configuration was already existing. No changes has been done.

I am able to run the project successfully after migration. All api end points are working fine. But unfortunately swagger stopped working.

Swagger error: enter image description here

I have gone through the lot of tutorials/blogs but not able to find the solution. Thanks everyone in advance.


Solution

  • In my case, it was due to conflict of org.reflections library. switched from 0.10 back to 0.9.12 fixed the issue.

    Recommendation for migration: Actually the problem was in technique of migration. We should not jump to latest version directly. We should continue version by version by considering the release notes. If you want to switch from spring 2.0.0 to 2.7.0, don't directly jump into it. Just move first 2.1.0..2.2.0.. etc. Clean and Build the project on each and every step of the migration.

    Thanks!!!