OpenAPI Swagger for springboot application

1.5k Views Asked by At

I've started to develop a small springboot application and I wanted to document it's API (every existing endpoint) using Swagger. However, doesn't matter which version of Swagger I'm trying to implement, I always end up with 404 response code while trying to access swagger-ui (and other endpoints provided by Swagger). I'd be thankful for help from someone who has successfully fixed that issue or have suspicions of how to fix it. I'll provide information about my project if needed.

I've tried different swagger versions, url mapping, different configurations (even tho in newer one apparently all i needed was the dependency, still didn't work tho).

https://github.com/ryszard-urbanek/movie-base - this is the current state of the project, below I give a code sample of what I'm trying to add

    @SpringBootApplication
@EnableSwagger2
public class MovieBaseApplication {
    @Bean
    public Docket get() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any()) // Updated path
                .build()
                .host("http://localhost:8080");
    }

    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(MovieBaseApplication.class, args);
    }
}


    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>3.0.0</version>
    </dependency>
1

There are 1 best solutions below

0
Gastón Schabas On

Springfox doesn't work with spring boot 3 yet

If you want to continue working with spring boot 3, you can use springdoc-openapi-starter-webmvc-ui.

Here you have an article that shows how to build a REST API with spring boot and springdoc

It should be pretty straightforward. Just adding the following dependency to your pom.xml

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.0</version>
</dependency>

and then the following properties to you yaml config file

springdoc:
    swagger-ui:
        path: /swagger.html
    api-docs:
        path: /docs