0

I am working on Spring MVC and trying to migrate Springfox v. 2.9.2 to 3.0.0. When I change the version to 3.0.0, it gives me error:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoClassDefFoundError: Could not initialize class springfox.documentation.schema.Types

Here is my dependency:

<swagger-version>3.0.0</swagger-version>
<swagger-version-ui>3.0.0</swagger-version-ui>
<swagger-annotations>2.1.11</swagger-annotations>

<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>${swagger-version}</version>
</dependency>
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>${swagger-version-ui}</version>
</dependency>
<dependency>
  <groupId>io.swagger.core.v3</groupId>
  <artifactId>swagger-annotations</artifactId>
  <version>${swagger-annotations}</version>
</dependency>

How to properly configure Springfox 3.0.0 in Spring MVC?

João Dias
  • 16,277
  • 6
  • 33
  • 45
Doctor Who
  • 747
  • 1
  • 5
  • 28
  • [Migrating from existing 2.x version](https://springfox.github.io/springfox/docs/current/#migrating-from-existing-2-x-version), welcome! ;* – xerx593 Nov 22 '21 at 17:16
  • Consider moving to `springdoc` instead of using `Springfox`. You can find more info [here](https://stackoverflow.com/a/69108852/16572295). – João Dias Nov 22 '21 at 18:42
  • @JoãoDias after integrating swagger page is showing 404, any idea about this, my project is not springboot application – Doctor Who Nov 23 '21 at 10:47
  • Unfortunately no, I've always used without any issues in Spring Boot applications. – João Dias Nov 23 '21 at 10:49

1 Answers1

0

Many resources on the Internet say that as long as the two packages springfox-swagger2 and springfox-swagger-ui are available. I found that if only these two packages are used to run the project, it will report ClassnotFoundException or NoSuchMethodException. Add little by little, and finally the actual imported package is as follows:

<spring.version>5.1.5.RELEASE</spring.version>
<spring.plugin.version>2.0.0.RELEASE</spring.plugin.version>
<swagger.version>3.0.0</swagger.version>
 <!-- swagger2 jar-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-common</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-web</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-core</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spi</artifactId>
            <version>${swagger.version}</version>
        </dependency>

        <!--spring plugin,configure swagger-->
        <dependency>
            <groupId>org.springframework.plugin</groupId>
            <artifactId>spring-plugin-core</artifactId>
            <version>${spring.plugin.version}</version>
        </dependency>

I didn't know the specific reason. But I tried it, if any package is missing, an error will be reported.

ganlana
  • 98
  • 1
  • 2
  • 5