Total Pageviews

2019/12/11

[Spring Boot] Enabling Swagger2

How To
1. Add dependency in your pom.xml
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>

2. Add @EnableSwagger2 annotation
package tw.com.xxx.analysis;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
public class AnalysisApplication {

    public static void main(String[] args) {
        SpringApplication.run(AnalysisApplication.class, args);
    }

}

3. Startup your spring boot project on the Tomcat port 8080

4. Check result: http://localhost:8080/swagger-ui.html
Swagger2 provides a user interface to access our RESTful web services via the web browser.


No comments: