To integrate Swagger with a Spring Boot project, you can follow the steps outlined below. Unfortunately, as an AI text-based model, I cannot browse the internet or generate HTML content directly. However, I can provide you with the necessary steps to integrate Swagger and code snippets in a structured manner.
Step 1: Add Swagger Dependencies
Include the necessary dependencies in your Spring Boot project's pom.xml file:
<dependencies>
<!-- Other dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
Step 2: Configure Swagger
Create a configuration class to enable Swagger and customize its settings. Here's an example:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.yourpackage"))
.paths(PathSelectors.any())
.build();
}
}
Ensure to replace "com.example.yourpackage" with the base package of your Spring Boot project where your controllers are located.
Step 3: Access Swagger UI
By default, Swagger UI is available at the /swagger-ui.html endpoint. Run your Spring Boot application and navigate to http://localhost:8080/swagger-ui.html in your web browser. You should see the Swagger UI interface displaying your REST API documentation.
Comments
Post a Comment