swagger Setup springfox using swagger-ui in spring-boot


  1. Get springfox into your application by using Maven or Gradle
  2. Create a new Docket bean in your application and configure it
  3. Document your API according to your needs
  4. Launch your application and see your achieved results

#1 Getting springfox with Maven

Add the dependencies for swagger2 and swagger-ui in your pom.xml


#2 Configure your application to use swagger

Add the annotation @EnableSwagger2 to your @SpringBootApplication annotated main class and create a swagger Docket bean within this (or any other) configuration class.

public Docket api() {                
    return new Docket(DocumentationType.SWAGGER_2)          

This configuration will generate an API documentation over all spring controllers within your application. If you need to limit the API documentation generation to certain controllers you can choose between various RequestHandlerSelectors. E.g. you can generate your API documentation based on your package structure using RequestHandlerSelectors.basePackage("your.package.structure") or based specific classes that you've annotated using RequestHandlerSelectors.withClassAnnotation(Api.class).

#3 Document your API

Use the annotations as described in the documentation, to enhance your controller classes and methods with additional information. To describe the general information of your api, like general title, description or the version, make use of the ApiInfoBuilder() within your Docket bean.

Example for the metadata definition using ApiInfoBuilder:

// Within your configuration class
public static ApiInfo metadata(){
    return new ApiInfoBuilder()
            .title("Your Title")
            .description("Your Description")

// Within your method that definies the Docket bean...