国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

swagger3 快速整合 springboot 2.6.15

這篇具有很好參考價值的文章主要介紹了swagger3 快速整合 springboot 2.6.15。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

參考:
https://swagger.io/
https://swagger.io/docs/
https://swagger.io/tools/swagger-ui/
https://github.com/swagger-api/swagger-core/wiki/
https://github.com/swagger-api/swagger-ui/wiki

http://springfox.github.io/springfox/
https://github.com/springfox/springfox
http://springfox.github.io/springfox/docs/current/
https://github.com/springfox/springfox-demos
https://github.com/springfox/springfox-demos/tree/2.9.2
https://github.com/springfox/springfox-demos/tree/3.0.0


1.引入依賴

    <!-- springfox-boot-starter -->
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-boot-starter</artifactId>
      <version>3.0.0</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>2.6.15</version>
    </dependency>


2.配置類

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 訪問:http://localhost:8080/swagger-ui/
 */
@Configuration
@EnableOpenApi
public class Swagger3Config {


    private String basePackage = "com.xxx.xxx.controller";


    @Bean
    public Docket createRestApi() {

        return new Docket(DocumentationType.OAS_30)
                .groupName("api")
                .enable(true) // .enable(!"prod".equals(active))
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(basePackage)) // 基于包掃描
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))  // 基于注解
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 基于注解
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("API 接口文檔")
                .description("Restful API 接口文檔")
                .version("1.0")
                .contact(new Contact("聯(lián)系人姓名","聯(lián)系人url","聯(lián)系人email"))
                .termsOfServiceUrl("服務(wù)條款URL")
                .license("xxx License Version 1.0")
                .licenseUrl("http://www.xxx.xxx/licenses/LICENSE-1.0")
                .build();
    }




    /**
     * 增加如下配置可解決Spring Boot 6.x 與Swagger 3.0.0 不兼容問題
     **/
    @Bean
    public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier,
                                                                         ServletEndpointsSupplier servletEndpointsSupplier,
                                                                         ControllerEndpointsSupplier controllerEndpointsSupplier,
                                                                         EndpointMediaTypes endpointMediaTypes,
                                                                         CorsEndpointProperties corsProperties,
                                                                         WebEndpointProperties webEndpointProperties,
                                                                         Environment environment) {
        List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
        Collection<ExposableWebEndpoint> 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));
    }

}



3.編寫代碼Controller

@Api(tags = "測試接口")
@Controller
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;


    @ApiOperation("set value 操作")
    @ResponseBody
    @RequestMapping(value = "/set", method = RequestMethod.POST)
    public String setVal(String key, String value) {

        redisTemplate.opsForValue().set(key, value);

        return "success set val";
    }

    @ApiOperation("get 操作")
    @ResponseBody
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public String getValue(String key) {

        String result = (String) redisTemplate.opsForValue().get(key);

        System.err.println("======> 返回結(jié)果result:" + result);

        return result;
    }


}


4.訪問與測試:http://localhost:8080/swagger-ui/



文章來源地址http://www.zghlxwxcb.cn/news/detail-681330.html

到了這里,關(guān)于swagger3 快速整合 springboot 2.6.15的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • SpringBoot3整合OpenAPI3(Swagger3)

    SpringBoot3整合OpenAPI3(Swagger3)

    swagger2 更新到3后,再使用方法上發(fā)生了很大的變化,名稱也變?yōu)?OpenAPI3 。 官方文檔 openapi3 使用十分方便,做到這里后,你可以直接通過以下網(wǎng)址訪問 swagger 頁面。 1. @OpenAPIDefinition + @Info 用于定義整個 API 的信息,通常放在主應(yīng)用類上??梢园?API 的標(biāo)題、描述、版本等信

    2024年01月22日
    瀏覽(21)
  • Spring Boot 3項目集成Swagger3教程

    歡迎來到我的小天地,這里是我記錄技術(shù)點滴、分享學(xué)習(xí)心得的地方。?? ??? 技能清單 編程語言 :Java、C、C++、Python、Go、 前端技術(shù) :Jquery、Vue.js、React、uni-app、Echarts UI設(shè)計 : Element-ui、Antd、Color-ui 后端技術(shù) :Spring Boot、Mybatis-plus、Swagger 移動開發(fā) :Android 操作系統(tǒng) :

    2024年04月17日
    瀏覽(22)
  • 【Spring Boot】SpringBoot 優(yōu)雅整合Swagger Api 自動生成文檔

    【Spring Boot】SpringBoot 優(yōu)雅整合Swagger Api 自動生成文檔

    Swagger 是一套 RESTful API 文檔生成工具,可以方便地生成 API 文檔并提供 API 調(diào)試頁面。 而 Spring Boot 是一款非常優(yōu)秀的 Java Web 開發(fā)框架,它可以非常方便地構(gòu)建 Web 應(yīng)用程序。 在本文中,我們將介紹如何使用 Swagger 以及如何在 Spring Boot 中整合 Swagger 。 首先,在 pom.xml 文件中添

    2023年04月22日
    瀏覽(25)
  • SpringCloudGateway整合swagger3文檔

    SpringCloudGateway整合swagger3文檔

    ? ? ? ? ?SpringCloud項目中,微服務(wù)模塊和網(wǎng)關(guān)模塊必不可少。按照以前SpringBoot的模式,單個服務(wù)擁有自己的Api文檔(Swagger文檔),引入微服務(wù)后,多文檔管理成了一個問題。我們需要一個統(tǒng)一的入口方便前端同學(xué)查看。本篇文章就是把各個微服務(wù)的swagger-api文檔,集成到網(wǎng)

    2024年02月09日
    瀏覽(21)
  • Spring Boot 整合 Swagger 教程詳解

    Spring Boot 整合 Swagger 教程詳解

    ?作者簡介:2022年 博客新星 第八 。熱愛國學(xué)的Java后端開發(fā)者,修心和技術(shù)同步精進。 ??個人主頁:Java Fans的博客 ??個人信條:不遷怒,不貳過。小知識,大智慧。 ??當(dāng)前專欄:SpringBoot 框架從入門到精通 ?特色專欄:國學(xué)周更-心性養(yǎng)成之路 ??本文內(nèi)容:Spring Boot 整

    2023年04月14日
    瀏覽(26)
  • Java技術(shù)-接口文檔-Swagger2&Swagger3&接口文檔UI整合

    Java技術(shù)-接口文檔-Swagger2&Swagger3&接口文檔UI整合

    目錄 一、Swagger2完整用法 1.POM依賴 2.接口類 3.實現(xiàn)類 4.托管靜態(tài)資源 5.接口文檔配置 6.生產(chǎn)環(huán)境關(guān)閉接口文檔 7.Swagger3頁面效果 二、Swagger3完整用法 三、Swagger整合Knife4jUi 1.POM依賴 2.接口類 3.實現(xiàn)類 4.托管靜態(tài)資源 5.接口文檔配置 6.生產(chǎn)環(huán)境關(guān)閉接口文檔 四、注釋和參數(shù)講解

    2024年02月16日
    瀏覽(31)
  • Spring Boot 整合 Swagger2 糾錯

    ????????因為我要建立的是微服務(wù)的項目,需要建立許多模塊,以至于我在父工程中引入了當(dāng)前模塊,然后我在子模塊中又引入了當(dāng)前模塊,造成了沖突。 ????????另外一種解決方法是,經(jīng)過上網(wǎng)查證,可能由于Spring Boot和Swagger版本的問題,Spring Boot2.6以上的版本,需要使用

    2024年02月12日
    瀏覽(21)
  • swagger 2.10.5 整合 spring boot

    2024年02月11日
    瀏覽(20)
  • Spring Boot整合Spring Fox生成Swagger文檔

    Spring Boot整合Spring Fox生成Swagger文檔

    Springfox是一個用于在Spring應(yīng)用程序中生成Swagger文檔的開源庫。它提供了一組注解和工具,可以將你的API代碼和文檔整合在一起,方便生成和展示API的Swagger文檔。 使用Springfox,你可以在Spring Boot項目中集成Swagger,并通過Swagger UI查看和測試API。它提供了一些注解,如 @Api 、 @

    2024年02月08日
    瀏覽(17)
  • spring boot 2.7.9 整合 Swagger 3.0

    spring boot 2.7.9 整合 Swagger 3.0

    ?jdk? 1.8 springboot 2.7.9 swagger 3.0.0 描述:Failed to start bean \\\'documentationPluginsBootstrapper\\\'; nested exception is java.lang.NullPointerException 沒有這個bean,空指針了。 據(jù)網(wǎng)上資料找,3.0的Swagger已經(jīng)不繼承WebMvcConfig這個類,是繼承了WebMvcConfigSupport類,從而改動了配置路徑規(guī)則,然后報空指針,

    2024年02月06日
    瀏覽(38)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包