Swagger API /v3/api-docs Error 404

Swagger API Error

You might have found the error 404 (not found) while trying to access the Swagger API docs (/v3/api-docs) for your REST APIs.

swagger api 404 error

You might have also found the following error while you check your logs:

java.lang.NoSuchMethodError: 'void org.springframework.web.method.ControllerAdviceBean.<init>(java.lang.Object)'

The error what you see above might be raised due to several reasons and one of the major reasons is:

You are using Spring Boot version 3.x.x and you are using the Swagger API version which is not compatible with the Spring Boot version.

Even when you are upgrading your Spring Boot version, for example, from Spring Boot 3.3.x to 3.4.x, then you might also face the similar compatibility issue.

Solution

You may try to upgrade your Swagger version to make it compatible with the Spring Boot version and the issue may go away.

For example, if you are using Spring Boot version 3.3.x, try to use the Swagger (springdoc-openapi v2) version 2.5.0 or 2.6.0.

You can use the following maven artifact for the Open API:

springdoc-openapi-starter-webmvc-ui

If you are using Spring Boot version 3.4.x, then you can use Swagger version 2.7.0 or 2.8.0 to make it compatible.

If the above solutions do not work then you can disable generic responses generated by springdoc using the @ControllerAdvice. You can do this by setting the following property in the application.properties file:

springdoc.override-with-generic-response=false

Now restart your application, your application should run.

Share

Related posts

No comments

Leave a comment