0

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>
rysiu115
  • 1
  • 1
  • We need much more info. pom.xml, source code of ‘@SpringbootApplication annotated class. Is the api docs json being returned? Just the JSON format, not the UI. – John Williams May 02 '23 at 18:45
  • please share more info. for example: whether it is a REST or GraphQL API, as configurations can vary depending on your project – Shourya Sharma May 04 '23 at 11:45
  • I've provided more information, will be thankful for a feedback – rysiu115 May 06 '23 at 17:34

1 Answers1

0

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
Gastón Schabas
  • 2,153
  • 1
  • 10
  • 17