当前位置: 首页 > news >正文

国家建设部网站注册工程师人员查询宣传平台的软件有哪些

国家建设部网站注册工程师人员查询,宣传平台的软件有哪些,百度网盘电脑网页版,怎么做vip视频网站一、starter实现统一配置微服务文档 把Swagger配置中的公共部分抽取出来Swagger与SpringBoot整合中#xff0c;可能会由于版本问题出现各种问题 1、制作starter 参考#xff1a; 【SpringBoot】自定义启动器 Starter【保姆级教程】用starter实现Oauth2中资源服务的统一配置用…一、starter实现统一配置微服务文档 把Swagger配置中的公共部分抽取出来Swagger与SpringBoot整合中可能会由于版本问题出现各种问题 1、制作starter 参考 【SpringBoot】自定义启动器 Starter【保姆级教程】用starter实现Oauth2中资源服务的统一配置用starter实现api接口的加密与日志功能用spring-boot-starter实现事务的统一配置 1 总体结构图 2 外部引用模块 tuwer-swagger-spring-boot-starter pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.tuwer/groupIdartifactIdtuwer-swagger-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/versiondescriptionswagger配置starter/descriptionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependencies!-- 自动配置模块 --dependencygroupIdcom.tuwer/groupIdartifactIdtuwer-swagger-spring-boot-starter-autoconfigure/artifactIdversion1.0-SNAPSHOT/version/dependency/dependencies /project3 自动配置模块 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.6.7/version/parentmodelVersion4.0.0/modelVersiongroupIdcom.tuwer/groupIdartifactIdtuwer-swagger-spring-boot-starter-autoconfigure/artifactIdversion1.0-SNAPSHOT/versiondescriptionswagger自动配置模块/descriptionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependencies!-- 基础启动器 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependency!-- web --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependency!-- Swagger --dependencygroupIdio.springfox/groupIdartifactIdspringfox-boot-starter/artifactIdversion3.0.0/version/dependency!-- actuator完善监控信息 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId/dependency!-- lombok --dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.22/version/dependency/dependencies /project自动配置类 不要加 EnableWebMvc package com.tuwer.config;import org.springframework.boot.actuate.autoconfigure.endpoint.web.CorsEndpointProperties; import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties; import org.springframework.boot.actuate.autoconfigure.web.server.ManagementPortType; import org.springframework.boot.actuate.endpoint.ExposableEndpoint; import org.springframework.boot.actuate.endpoint.web.*; import org.springframework.boot.actuate.endpoint.web.annotation.ControllerEndpointsSupplier; import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpointsSupplier; import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.util.StringUtils; 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 javax.annotation.Resource; import java.util.ArrayList; import java.util.Collection; import java.util.List;/*** author 土味儿* Date 2023/4/21* version 1.0* 这里不要加EnableWebMvc注解否则响应数据会出现乱码*/ Configuration //EnableWebMvc EnableConfigurationProperties(SwaggerProperty.class) public class SwaggerConfig {ResourceSwaggerProperty swaggerProperty;/*** 配置Swagger具体参数** return*/Beanpublic Docket docket(Environment environment) {// 允许启用Swagger的环境//Profiles profile Profiles.of(dev,test);// 判断当前环境与指定环境是否一致//boolean b environment.acceptsProfiles(profile);//return new Docket(DocumentationType.OAS_30)return new Docket(DocumentationType.SWAGGER_2)//.apiInfo(apiInfo(tuwer, 搜索服务, v3.0)).apiInfo(apiInfo(swaggerProperty.getAuthor(), swaggerProperty.getTitle(), swaggerProperty.getVersion()))// 根据当前环境判断是否启用Swagger//.enable(b)//.enable(true)//.groupName(A)// 通过.select()方法去配置扫描接口,RequestHandlerSelectors配置如何扫描接口.select()// 只扫描特定包下的接口.apis(RequestHandlerSelectors.basePackage(swaggerProperty.getBasePackage()))//.apis(RequestHandlerSelectors.any())//.apis(RequestHandlerSelectors.none())//.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))//.apis(RequestHandlerSelectors.withMethodAnnotation(GetMapping.class))//.paths(PathSelectors.).build();}/*** 自定义API文档信息** return*/private ApiInfo apiInfo(String author, String title, String version) {// 作者信息Contact contact new Contact(author, , );return new ApiInfo(title API 文档,,version,,contact,,,new ArrayList());}/*** 增加如下配置可解决Spring Boot 2.6.x 与 Swagger 3.0.0 不兼容问题* ------------------------------------------* 还需要在yml中作如下配置* mvc:* pathmatch:* matching-strategy: ant_path_matcher**/Beanpublic WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,ServletEndpointsSupplier servletEndpointsSupplier,ControllerEndpointsSupplier controllerEndpointsSupplier,EndpointMediaTypes endpointMediaTypes,CorsEndpointProperties corsProperties,WebEndpointProperties webEndpointProperties,Environment environment) {ListExposableEndpoint? allEndpoints new ArrayList();CollectionExposableWebEndpoint webEndpoints webEndpointsSupplier.getEndpoints();allEndpoints.addAll(webEndpoints);allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());String basePath webEndpointProperties.getBasePath();EndpointMapping endpointMapping new EndpointMapping(basePath);boolean shouldRegisterLinksMapping this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);}private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {return webEndpointProperties.getDiscovery().isEnabled() (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));}}配置属性类 package com.tuwer.config;import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties;/*** p配置属性类/p** author 土味儿* version 1.0* Date 2023/4/22*/ Data ConfigurationProperties(prefix tuwer-swagger) public class SwaggerProperty {String author;String title;String version;String basePackage; }2、微服务使用starter 1 注入依赖 需要使用swagger的服务注入 !-- Swagger -- dependencygroupIdcom.tuwer/groupIdartifactIdtuwer-swagger-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/version /dependency2 添加配置 spring:mvc:pathmatch:# swagger3.0需要ant_path_matcher# springboot2.6后默认为path_pattern_parsermatching-strategy: ant_path_matcher# swagger配置 tuwer-swagger:author: 作者title: 服务名称version: 版本base-package: 基础包 3 接口中添加API文档信息 API接口中添加 // 示例 RestController Api(tags 接口类描述) public class TestApi {PostMapping(/...)ApiOperation(接口方法描述)public String test(ApiParam(参数描述)RequestParam(id) Long id) {// ...} } 至此用starter实现微服务的swagger配置完成 二、网关聚合文档 使用 spring-cloud-gateway 网关把各个微服务的文档聚合起来通过网关统一访问。 参考聚合微服务中的 Swagger API 文档 1、注入依赖 在网关服务中加入Swagger依赖 更加细致的设计思路网上有介绍微服务中不需要Swagger的ui包只要能生成api的json数据包供网关抓取就可以。同时网关中也不用自已成生api的json数据包也可以去掉一些相关的依赖包。 !-- Swagger -- dependencygroupIdio.springfox/groupIdartifactIdspringfox-boot-starter/artifactIdversion3.0.0/version /dependency2、配置网关 不是所有的服务都通过网关转发。有些内部服务可以通过docker的内部网络直接访问可以单独配置这类内部服务的API文档。 spring:# 配置 Spring Cloud 相关属性cloud:# 配置 Spring Cloud Gateway 相关属性gateway:# 配置网关发现机制discovery:# 配置处理机制locator:enabled: false# 开启服务名称小写转换默认为falselower-case-service-id: true# 路由配置routes:# 正常服务1- id: server-1uri: 转发地址predicates:- Path/server_1/**- MethodGET,POSTfilters:- name: StripPrefixargs:# 过滤掉前1节parts: 1# 正常服务2- id: server-2uri: 转发地址predicates:- Path/server_2/**- MethodGET,POSTfilters:- name: StripPrefixargs:# 过滤掉前1节parts: 1# swagger文档1- id: swagger-docs-1uri: 转发地址predicates:- Path/swagger_1/**- MethodGET,POSTfilters:- name: StripPrefixargs:# 过滤掉前1节parts: 1# swagger文档2- id: swagger-docs-2uri: 转发地址predicates:- Path/swagger_2/**- MethodGET,POSTfilters:- name: StripPrefixargs:# 过滤掉前1节parts: 13、Swagger资源抓取类 从网关配置中过滤出Swagger的API文档配置信息 package com.tuwer.config;import lombok.AllArgsConstructor; import org.springframework.cloud.gateway.config.GatewayProperties; import org.springframework.cloud.gateway.route.RouteLocator; import org.springframework.cloud.gateway.support.NameUtils; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import springfox.documentation.swagger.web.SwaggerResource; import springfox.documentation.swagger.web.SwaggerResourcesProvider;import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Objects;/*** pSwagger资源类/p** author 土味儿* version 1.0* Date 2023/4/22*/ Component Primary AllArgsConstructor SuppressWarnings(all) public class SwaggerResourceConfig implements SwaggerResourcesProvider {private final RouteLocator routeLocator;private final GatewayProperties gatewayProperties;Overridepublic ListSwaggerResource get() {ListSwaggerResource resources new ArrayList();ListString routes new ArrayList();// 获取所有swagger文档路由的IDrouteLocator.getRoutes().subscribe(route - {String routeId route.getId().toLowerCase(Locale.ROOT);// swagger文档的路由ID中包含有swagger-docsif (routeId.contains(swagger-docs)) {routes.add(route.getId());}});//过滤出配置文件中定义的路由-过滤出Path Route Predicate-根据路径拼接成api-docs路径-生成SwaggerResourcegatewayProperties.getRoutes().stream().filter(routeDefinition - routes.contains(routeDefinition.getId())).forEach(route - {route.getPredicates().stream().filter(predicateDefinition - (Path).equalsIgnoreCase(predicateDefinition.getName())).forEach(predicateDefinition -resources.add(swaggerResource(route.getId(),predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX 0)// 把路径中后面的 ** 替换成文档地址v2/api-docs.replace(**, v2/api-docs))));});return resources;}private SwaggerResource swaggerResource(String name, String location) {//log.info(name:{},location:{}, name, location);SwaggerResource swaggerResource new SwaggerResource();swaggerResource.setName(SwaggerModel.getByName(name).cnName);swaggerResource.setLocation(location);swaggerResource.setSwaggerVersion(2.0);return swaggerResource;}/*** 枚举类中英文映射*/enum SwaggerModel {DEFAULT(default, 默认),S_1(swagger-docs-1, 文档1),S_2(swagger-docs-2, 文档2);private String name;private String cnName;SwaggerModel(String name, String cnName) {this.name name;this.cnName cnName;}public static SwaggerModel getByName(String name) {for (SwaggerModel m : SwaggerModel.values()) {if (Objects.equals(m.name, name)) {//if(m.code code){return m;}}return DEFAULT;}} }
http://www.w-s-a.com/news/360370/

相关文章:

  • 嘉兴港区建设局网站2018年网站开发
  • 网站里图片做超链接专业开发网站报价单
  • server2003网站建设做销售记住这十句口诀
  • microsoft免费网站网站后台登陆路径
  • 贵州住房和城乡建设局网站做网站排名费用多少钱
  • 现在个人做网站还能盈利吗xampp用wordpress
  • 做网站 租服务器温岭建设公司网站
  • 四川住房和城乡建设厅网站官网做网站最贵
  • 右玉网站建设四川林峰脉建设工程有限公司网站
  • 网站推广小助手杭州百度百家号seo优化排名
  • 怎么做网站搜索框搜索网站备案拍照背景幕布
  • 建设部网站城市规划资质标准伊春网络推广
  • 如何设计酒店网站建设深圳市房地产信息系统平台
  • 伍佰亿网站怎么样网站建设前台后台设计
  • 做整装的网站北京哪个网站制作公司
  • 建设赚钱的网站福州便民生活网
  • 咸阳网站设计建设公司小程序打包成app
  • 做视频网站视频文件都存放在哪做旅游宣传图的网站有哪些
  • 地方门户类网站产品推广惠州市中国建设银行网站
  • 网站建设公司推荐5788移动版wordpress
  • 产品类型 速成网站淘宝怎么建立自己的网站
  • 南京优化网站建设公司的网站怎么建设
  • 做网站开发能挣钱月嫂云商城网站建设
  • 包装网站模板新手入门网站建设
  • 做网站的天津哪个公司做网站
  • 网站建设摊销时间是多久微信官网免费下载安装
  • 网站解析是做a记录吗群晖 wordpress 阿里云
  • 涉县移动网站建设公司常州做网站的公司有哪些
  • 网站批量创建程序中国十大人力资源公司
  • 菏泽网站建设 梧桐树二次开发创造作用