diff --git a/jeecg-boot-base-core/pom.xml b/jeecg-boot-base-core/pom.xml index bf2fe06d01..250a987ddc 100644 --- a/jeecg-boot-base-core/pom.xml +++ b/jeecg-boot-base-core/pom.xml @@ -185,7 +185,7 @@ com.github.xiaoymin - knife4j-spring-boot-starter + knife4j-openapi3-spring-boot-starter ${knife4j-spring-boot-starter.version} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger2Config.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger2Config.java index 92e962e154..484624b965 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger2Config.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger2Config.java @@ -1,183 +1,182 @@ -package org.jeecg.config; - - -import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; -import io.swagger.annotations.ApiOperation; -import org.jeecg.common.constant.CommonConstant; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.util.ReflectionUtils; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; -import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.ParameterBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.oas.annotations.EnableOpenApi; -import springfox.documentation.schema.ModelRef; -import springfox.documentation.service.*; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spi.service.contexts.SecurityContext; -import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider; -import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider; -import springfox.documentation.swagger2.annotations.EnableSwagger2; - -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @Author scott - */ -@Configuration -@EnableSwagger2 //开启 Swagger2 -@EnableKnife4j //开启 knife4j,可以不写 -@Import(BeanValidatorPluginsConfiguration.class) -public class Swagger2Config implements WebMvcConfigurer { - - /** - * - * 显示swagger-ui.html文档展示页,还必须注入swagger资源: - * - * @param registry - */ - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); - } - - /** - * swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等 - * - * @return Docket - */ - @Bean(value = "defaultApi2") - public Docket defaultApi2() { - return new Docket(DocumentationType.SWAGGER_2) - .apiInfo(apiInfo()) - .select() - //此包路径下的类,才生成接口文档 - .apis(RequestHandlerSelectors.basePackage("org.jeecg")) - //加了ApiOperation注解的类,才生成接口文档 - .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) - .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) - .paths(PathSelectors.any()) - .build() - .securitySchemes(Collections.singletonList(securityScheme())) - .securityContexts(securityContexts()) - .globalOperationParameters(setHeaderToken()); - } - - /*** - * oauth2配置 - * 需要增加swagger授权回调地址 - * http://localhost:8888/webjars/springfox-swagger-ui/o2c.html - * @return - */ - @Bean - SecurityScheme securityScheme() { - return new ApiKey(CommonConstant.X_ACCESS_TOKEN, CommonConstant.X_ACCESS_TOKEN, "header"); - } - /** - * JWT token - * @return - */ - private List setHeaderToken() { - ParameterBuilder tokenPar = new ParameterBuilder(); - List pars = new ArrayList<>(); - tokenPar.name(CommonConstant.X_ACCESS_TOKEN).description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); - pars.add(tokenPar.build()); - return pars; - } - - /** - * api文档的详细信息函数,注意这里的注解引用的是哪个 - * - * @return - */ - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - // //大标题 - .title("JeecgBoot 后台服务API接口文档") - // 版本号 - .version("1.0") -// .termsOfServiceUrl("NO terms of service") - // 描述 - .description("后台API接口") - // 作者 - .contact(new Contact("北京国炬信息技术有限公司","www.jeccg.com","jeecgos@163.com")) - .license("The Apache License, Version 2.0") - .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") - .build(); - } - - /** - * 新增 securityContexts 保持登录状态 - */ - private List securityContexts() { - return new ArrayList( - Collections.singleton(SecurityContext.builder() - .securityReferences(defaultAuth()) - .forPaths(PathSelectors.regex("^(?!auth).*$")) - .build()) - ); - } - - private List defaultAuth() { - AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); - AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; - authorizationScopes[0] = authorizationScope; - return new ArrayList( - Collections.singleton(new SecurityReference(CommonConstant.X_ACCESS_TOKEN, authorizationScopes))); - } - - /** - * 解决springboot2.6 和springfox不兼容问题 - * @return - */ - @Bean - public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() { - return new BeanPostProcessor() { - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) { - customizeSpringfoxHandlerMappings(getHandlerMappings(bean)); - } - return bean; - } - - private void customizeSpringfoxHandlerMappings(List mappings) { - List copy = mappings.stream() - .filter(mapping -> mapping.getPatternParser() == null) - .collect(Collectors.toList()); - mappings.clear(); - mappings.addAll(copy); - } - - @SuppressWarnings("unchecked") - private List getHandlerMappings(Object bean) { - try { - Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); - field.setAccessible(true); - return (List) field.get(bean); - } catch (IllegalArgumentException | IllegalAccessException e) { - throw new IllegalStateException(e); - } - } - }; - } - - -} +//package org.jeecg.config; +// +// +//import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; +//import org.jeecg.common.constant.CommonConstant; +//import org.springframework.beans.BeansException; +//import org.springframework.beans.factory.config.BeanPostProcessor; +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.context.annotation.Import; +//import org.springframework.util.ReflectionUtils; +//import org.springframework.web.bind.annotation.RestController; +//import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +//import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; +//import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; +//import springfox.documentation.builders.ApiInfoBuilder; +//import springfox.documentation.builders.ParameterBuilder; +//import springfox.documentation.builders.PathSelectors; +//import springfox.documentation.builders.RequestHandlerSelectors; +//import springfox.documentation.oas.annotations.EnableOpenApi; +//import springfox.documentation.schema.ModelRef; +//import springfox.documentation.service.*; +//import springfox.documentation.spi.DocumentationType; +//import springfox.documentation.spi.service.contexts.SecurityContext; +//import springfox.documentation.spring.web.plugins.Docket; +//import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider; +//import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider; +//import springfox.documentation.swagger2.annotations.EnableSwagger2; +// +//import java.lang.reflect.Field; +//import java.util.ArrayList; +//import java.util.Collections; +//import java.util.List; +//import java.util.stream.Collectors; +// +///** +// * @Author scott +// */ +//@Configuration +//@EnableSwagger2 //开启 Swagger2 +//@EnableKnife4j //开启 knife4j,可以不写 +//@Import(BeanValidatorPluginsConfiguration.class) +//public class Swagger2Config implements WebMvcConfigurer { +// +// /** +// * +// * 显示swagger-ui.html文档展示页,还必须注入swagger资源: +// * +// * @param registry +// */ +// @Override +// public void addResourceHandlers(ResourceHandlerRegistry registry) { +// registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); +// registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); +// registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); +// } +// +// /** +// * swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等 +// * +// * @return Docket +// */ +// @Bean(value = "defaultApi2") +// public Docket defaultApi2() { +// return new Docket(DocumentationType.SWAGGER_2) +// .apiInfo(apiInfo()) +// .select() +// //此包路径下的类,才生成接口文档 +// .apis(RequestHandlerSelectors.basePackage("org.jeecg")) +// //加了ApiOperation注解的类,才生成接口文档 +// .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) +// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) +// .paths(PathSelectors.any()) +// .build() +// .securitySchemes(Collections.singletonList(securityScheme())) +// .securityContexts(securityContexts()) +// .globalOperationParameters(setHeaderToken()); +// } +// +// /*** +// * oauth2配置 +// * 需要增加swagger授权回调地址 +// * http://localhost:8888/webjars/springfox-swagger-ui/o2c.html +// * @return +// */ +// @Bean +// SecurityScheme securityScheme() { +// return new ApiKey(CommonConstant.X_ACCESS_TOKEN, CommonConstant.X_ACCESS_TOKEN, "header"); +// } +// /** +// * JWT token +// * @return +// */ +// private List setHeaderToken() { +// ParameterBuilder tokenPar = new ParameterBuilder(); +// List pars = new ArrayList<>(); +// tokenPar.name(CommonConstant.X_ACCESS_TOKEN).description("token").modelRef(new ModelRef("string")).parameterType("header").required(false).build(); +// pars.add(tokenPar.build()); +// return pars; +// } +// +// /** +// * api文档的详细信息函数,注意这里的注解引用的是哪个 +// * +// * @return +// */ +// private ApiInfo apiInfo() { +// return new ApiInfoBuilder() +// // //大标题 +// .title("JeecgBoot 后台服务API接口文档") +// // 版本号 +// .version("1.0") +//// .termsOfServiceUrl("NO terms of service") +// // 描述 +// .description("后台API接口") +// // 作者 +// .contact(new Contact("北京国炬信息技术有限公司","www.jeccg.com","jeecgos@163.com")) +// .license("The Apache License, Version 2.0") +// .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html") +// .build(); +// } +// +// /** +// * 新增 securityContexts 保持登录状态 +// */ +// private List securityContexts() { +// return new ArrayList( +// Collections.singleton(SecurityContext.builder() +// .securityReferences(defaultAuth()) +// .forPaths(PathSelectors.regex("^(?!auth).*$")) +// .build()) +// ); +// } +// +// private List defaultAuth() { +// AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); +// AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; +// authorizationScopes[0] = authorizationScope; +// return new ArrayList( +// Collections.singleton(new SecurityReference(CommonConstant.X_ACCESS_TOKEN, authorizationScopes))); +// } +// +// /** +// * 解决springboot2.6 和springfox不兼容问题 +// * @return +// */ +// @Bean +// public static BeanPostProcessor springfoxHandlerProviderBeanPostProcessor() { +// return new BeanPostProcessor() { +// +// @Override +// public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { +// if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) { +// customizeSpringfoxHandlerMappings(getHandlerMappings(bean)); +// } +// return bean; +// } +// +// private void customizeSpringfoxHandlerMappings(List mappings) { +// List copy = mappings.stream() +// .filter(mapping -> mapping.getPatternParser() == null) +// .collect(Collectors.toList()); +// mappings.clear(); +// mappings.addAll(copy); +// } +// +// @SuppressWarnings("unchecked") +// private List getHandlerMappings(Object bean) { +// try { +// Field field = ReflectionUtils.findField(bean.getClass(), "handlerMappings"); +// field.setAccessible(true); +// return (List) field.get(bean); +// } catch (IllegalArgumentException | IllegalAccessException e) { +// throw new IllegalStateException(e); +// } +// } +// }; +// } +// +// +//} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger3Config.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger3Config.java new file mode 100644 index 0000000000..044e9d6f22 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger3Config.java @@ -0,0 +1,58 @@ +package org.jeecg.config; + +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.Paths; +import io.swagger.v3.oas.models.info.Contact; +import io.swagger.v3.oas.models.info.Info; +import io.swagger.v3.oas.models.info.License; +import io.swagger.v3.oas.models.security.SecurityRequirement; +import io.swagger.v3.oas.models.security.SecurityScheme; +import org.jeecg.common.constant.CommonConstant; +import org.springdoc.core.GroupedOpenApi; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpHeaders; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +/** + * @author eightmonth + */ +@Configuration +public class Swagger3Config implements WebMvcConfigurer { + /** + * + * 显示swagger-ui.html文档展示页,还必须注入swagger资源: + * + * @param registry + */ + @Override + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/"); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); + } + + @Bean + public GroupedOpenApi swaggerOpenApi() { + return GroupedOpenApi.builder() + .group("default") + .packagesToScan("org.jeecg") + .build(); + } + + @Bean + public OpenAPI customOpenAPI() { + return new OpenAPI() + .info(new Info() + .title("JeecgBoot 后台服务API接口文档") + .version("1.0") + .contact(new Contact().name("北京国炬信息技术有限公司").url("www.jeccg.com").email("jeecgos@163.com")) + .description( "后台API接口") + .termsOfService("NO terms of service") + .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0.html"))) + .addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION)) + .components(new Components().addSecuritySchemes(HttpHeaders.AUTHORIZATION, + new SecurityScheme().name(HttpHeaders.AUTHORIZATION).type(SecurityScheme.Type.HTTP))); + } +} diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java b/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java index 4ca3ddf572..1f85af727d 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java @@ -120,7 +120,7 @@ public ShiroFilterFactoryBean shiroFilter(SecurityManager securityManager) { filterChainDefinitionMap.put("/swagger-ui.html", "anon"); filterChainDefinitionMap.put("/swagger**/**", "anon"); filterChainDefinitionMap.put("/webjars/**", "anon"); - filterChainDefinitionMap.put("/v2/**", "anon"); + filterChainDefinitionMap.put("/v3/**", "anon"); // 企业微信证书排除 filterChainDefinitionMap.put("/WW_verify*", "anon"); diff --git a/jeecg-server-cloud/jeecg-cloud-gateway/pom.xml b/jeecg-server-cloud/jeecg-cloud-gateway/pom.xml index 94e14d246c..97856645a2 100644 --- a/jeecg-server-cloud/jeecg-cloud-gateway/pom.xml +++ b/jeecg-server-cloud/jeecg-cloud-gateway/pom.xml @@ -73,7 +73,7 @@ com.github.xiaoymin - knife4j-spring-boot-starter + knife4j-gateway-spring-boot-starter ${knife4j-spring-boot-starter.version} diff --git a/jeecg-server-cloud/jeecg-cloud-gateway/src/main/resources/application.yml b/jeecg-server-cloud/jeecg-cloud-gateway/src/main/resources/application.yml index 6a1c492270..310f3f2174 100644 --- a/jeecg-server-cloud/jeecg-cloud-gateway/src/main/resources/application.yml +++ b/jeecg-server-cloud/jeecg-cloud-gateway/src/main/resources/application.yml @@ -1,6 +1,15 @@ server: port: 9999 +knife4j: + gateway: + enabled: true + strategy: discover + discover: + excluded-services: ${spring.application.name} + enabled: true + version: OpenAPI3 + spring: application: name: jeecg-gateway diff --git a/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml b/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml index 3d939c0d96..a201757a75 100644 --- a/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml +++ b/jeecg-server-cloud/jeecg-visual/jeecg-cloud-monitor/pom.xml @@ -34,17 +34,6 @@ org.springframework.boot spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-tomcat - - - - - - org.springframework.boot - spring-boot-starter-undertow diff --git a/pom.xml b/pom.xml index 135ee47459..530dd2105e 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ 2.2.0 1.2.83 1.6.0 - 3.0.3 + 4.3.0 2.0.9 42.2.25