diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java index fbe6661c..5f32006e 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/MafAutoConfiguration.java @@ -51,10 +51,6 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; import javax.annotation.PostConstruct; import java.io.File; @@ -71,7 +67,7 @@ @ConditionalOnWebApplication @AutoConfigureOrder(Integer.MIN_VALUE) @EnableConfigurationProperties(MafConfiguration.class) -@Import({MyBatisPlusConfiguration.class}) +@Import({MyBatisPlusConfiguration.class, Swagger2Configuration.class}) public class MafAutoConfiguration { @PostConstruct public void postConstruct() { @@ -159,25 +155,6 @@ public HttpApiResourceRemoteApiController httpApiResourceRemoteController(MafCon return new HttpApiResourceRemoteApiController(mafConfiguration, httpApiScanHelper); } - @Bean - @ConditionalOnProperty(value = "maf.configuration.swagger-disabled", havingValue = "false") - public Swagger2Configuration swagger2Configuration(MafProjectProperty mafProjectProperty) { - log.warn("Initial bean: '{}'", Swagger2Configuration.class.getSimpleName()); - return new Swagger2Configuration(mafProjectProperty); - } - - @Bean - @ConditionalOnProperty(value = "maf.configuration.swagger-disabled", havingValue = "false") - public Docket docket(Swagger2Configuration swagger2Configuration, MafProjectProperty mafProjectProperty) { - log.warn("Initial bean: '{}'", Docket.class.getSimpleName()); - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(swagger2Configuration.apiInfo()) - .select() - .apis(RequestHandlerSelectors.basePackage(mafProjectProperty.getBasePackage())) - .paths(PathSelectors.any()) - .build(); - } - @Bean public CommonService commonService(MafProjectProperty mafProjectProperty) { log.warn("Initial bean: '{}'", CommonServiceImpl.class.getSimpleName()); diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafConfiguration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafConfiguration.java index 8ac197a3..a0084a3d 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafConfiguration.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/MafConfiguration.java @@ -59,7 +59,7 @@ public class MafConfiguration { * Swagger disabled. true: disabled; false: enabled. */ @NotNull - private Boolean swaggerDisabled; + private Boolean swaggerDisabled = false; /** * Flatten ignored urls string [ ]. diff --git a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/Swagger2Configuration.java b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/Swagger2Configuration.java index 80e6caaa..a6dea220 100644 --- a/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/Swagger2Configuration.java +++ b/spring-boot-starter/src/main/java/com/jmsoftware/maf/springbootstarter/configuration/Swagger2Configuration.java @@ -3,10 +3,16 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import lombok.val; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; import javax.annotation.PostConstruct; @@ -24,6 +30,7 @@ @Configuration @EnableSwagger2 @RequiredArgsConstructor +@ConditionalOnProperty(value = "maf.configuration.swagger-disabled", havingValue = "false") public class Swagger2Configuration { private final MafProjectProperty mafProjectProperty; @@ -51,4 +58,15 @@ public ApiInfo apiInfo() { .version(version) .build(); } + + @Bean + public Docket docket(Swagger2Configuration swagger2Configuration, MafProjectProperty mafProjectProperty) { + log.warn("Initial bean: '{}'", Docket.class.getSimpleName()); + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(swagger2Configuration.apiInfo()) + .select() + .apis(RequestHandlerSelectors.basePackage(mafProjectProperty.getBasePackage())) + .paths(PathSelectors.any()) + .build(); + } }