Spring Boot + Profiles
Spring Boot Swagger- Table of Contents
Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot + Swagger + Profile - Implementing Spring Boot Profile for a Swagger application Spring Boot + Swagger 3 (OpenAPI 3) Hello World Example
Video
This tutorial is explained in the below Youtube Video.Lets Begin-
The project will be as follows-

We will define the Spring Profile for the Swagger implementation class SwaggerConfig such that it will get loaded only when the deployment is for QA else it will be disabled. For this in the application.properties file define the active profiles as follows-
spring.profiles.active=swagger-disabled-for-qa
The SwaggerConfig class annoatate with the Profile tag as follows-
package com.javainuse.swaggertest; import static com.google.common.base.Predicates.or; import static springfox.documentation.builders.PathSelectors.regex; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; import com.google.common.base.Predicate; @Profile("swagger-enabled-for-qa") @Configuration @EnableSwagger2 public class SwaggerConfig { @Bean public Docket postsApi() { return new Docket(DocumentationType.SWAGGER_2).groupName("public-api") .apiInfo(apiInfo()).select().paths(postPaths()).build(); } private PredicatepostPaths() { return or(regex("/api/posts.*"), regex("/api/javainuse.*")); } private ApiInfo apiInfo() { return new ApiInfoBuilder().title("JavaInUse API") .description("JavaInUse API reference for developers") .termsOfServiceUrl("http://javainuse.com") .contact("javainuse@gmail.com").license("JavaInUse License") .licenseUrl("javainuse@gmail.com").version("1.0").build(); } }
