Spring boot enable openapi swagger accessed

  1. Add the necessary dependencies to your Spring Boot project's pom.xml file:
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.6.5</version> <!-- Use the latest version available -->
</dependency>
  1. Create a configuration class to customize the OpenAPI documentation. Annotate the class with @Configuration and extend WebMvcConfigurerAdapter:
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class SwaggerConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui/")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springdoc-openapi-ui/")
                .resourceChain(false);
    }
}
  1. Optionally, customize the OpenAPI documentation by adding application.properties or application.yml configuration:
springdoc:
  api-docs:
    path: /api-docs # Customize the path to access the OpenAPI JSON documentation
  swagger-ui:
    path: /swagger-ui.html # Customize the path to access the Swagger UI
  1. Run your Spring Boot application.

  2. Access the Swagger UI by navigating to the specified path (default is http://localhost:8080/swagger-ui.html) in your web browser.

  3. Explore the API documentation using the Swagger UI interface.

Note: Make sure your controllers and APIs are properly annotated with Swagger annotations such as @ApiOperation, @ApiResponse, and others to provide detailed information in the generated Swagger documentation.