diff --git a/knife4j/knife4j-openapi3-jakarta-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java b/knife4j/knife4j-openapi3-jakarta-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java index f67fbf8b..d8f33372 100644 --- a/knife4j/knife4j-openapi3-jakarta-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java +++ b/knife4j/knife4j-openapi3-jakarta-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java @@ -28,6 +28,7 @@ import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springdoc.core.properties.SpringDocConfigProperties; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -51,10 +52,10 @@ @EnableConfigurationProperties({Knife4jProperties.class, Knife4jSetting.class, Knife4jHttpBasic.class}) @ConditionalOnProperty(name = "knife4j.enable", havingValue = "true") public class Knife4jAutoConfiguration { - + private final Knife4jProperties properties; private final Environment environment; - + /** * 增强自定义配置 * @return @@ -65,7 +66,7 @@ public Knife4jOpenApiCustomizer knife4jOpenApiCustomizer(SpringDocConfigProperti log.debug("Register Knife4jOpenApiCustomizer"); return new Knife4jOpenApiCustomizer(this.properties, docProperties); } - + @Bean @ConditionalOnMissingBean public Knife4jJakartaOperationCustomizer knife4jJakartaOperationCustomizer() { @@ -93,7 +94,7 @@ public CorsFilter corsFilter() { CorsFilter corsFilter = new CorsFilter(source); return corsFilter; } - + /** * Security with Basic Http * @param knife4jProperties Basic Properties @@ -101,7 +102,7 @@ public CorsFilter corsFilter() { */ @Bean @ConditionalOnMissingBean(JakartaServletSecurityBasicAuthFilter.class) - @ConditionalOnProperty(name = "knife4j.basic.enable", havingValue = "true") + @ConditionalOnExpression("${knife4j.production:false} && ${knife4j.basic.enable:true}") public FilterRegistrationBean securityBasicAuthFilter(Knife4jProperties knife4jProperties) { JakartaServletSecurityBasicAuthFilter authFilter = new JakartaServletSecurityBasicAuthFilter(); if (knife4jProperties == null) { @@ -127,7 +128,7 @@ public FilterRegistrationBean securityBas registration.setOrder(AbstractSecurityFilter.SPRING_FILTER_ORDER); return registration; } - + @Bean @ConditionalOnMissingBean(JakartaProductionSecurityFilter.class) @ConditionalOnProperty(name = "knife4j.production", havingValue = "true") @@ -152,5 +153,5 @@ public FilterRegistrationBean productionSecurit registration.setOrder(AbstractSecurityFilter.SPRING_FILTER_ORDER - 1); return registration; } - + } diff --git a/knife4j/knife4j-openapi3-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java b/knife4j/knife4j-openapi3-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java index e5cd6dfd..e04c014f 100644 --- a/knife4j/knife4j-openapi3-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java +++ b/knife4j/knife4j-openapi3-spring-boot-starter/src/main/java/com/github/xiaoymin/knife4j/spring/configuration/Knife4jAutoConfiguration.java @@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory; import org.springdoc.core.SpringDocConfigProperties; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; @@ -105,7 +106,7 @@ public CorsFilter corsFilter() { */ @Bean @ConditionalOnMissingBean(ServletSecurityBasicAuthFilter.class) - @ConditionalOnProperty(name = "knife4j.basic.enable", havingValue = "true") + @ConditionalOnExpression("${knife4j.production:false} && ${knife4j.basic.enable:true}") public FilterRegistrationBean securityBasicAuthFilter(Knife4jProperties knife4jProperties) { ServletSecurityBasicAuthFilter authFilter = new ServletSecurityBasicAuthFilter(); if (knife4jProperties == null) {