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

SpringBoot - 集成Swagger2、Knife4j接口文檔/升級(jí)版swagger-bootstrap-ui配置以及賬號(hào)密碼登錄

這篇具有很好參考價(jià)值的文章主要介紹了SpringBoot - 集成Swagger2、Knife4j接口文檔/升級(jí)版swagger-bootstrap-ui配置以及賬號(hào)密碼登錄。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

SpringBoot - 集成Swagger2、Knife4j接口文檔/升級(jí)版swagger-bootstrap-ui配置以及賬號(hào)密碼登錄

pom引入

<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>knife4j-spring-boot-starter</artifactId>
    <version>1.9.6</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!--原生swagger ui-->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
    <exclusions>
        <exclusion>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </exclusion>
    </exclusions>
</dependency>

配置類SwaggerConfig

package your.package.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
        		.apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("your.package.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    
    /**
     * API 說明,包含作者、簡(jiǎn)介、版本、host、服務(wù)URL
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("XXXAPI文檔")
                .description("XXXAPI文檔")
                //.contact(new Contact("API文檔", "http://www.XXX.com/", "xxx@qq.com"))//作者信息
                //.version("1.0")//定義api 版本號(hào)
                .build();
    }
}

請(qǐng)注意@Configuration和@EnableSwagger2注解。這兩個(gè)注解分別表示這是一個(gè)配置類,以及啟用了Swagger 2。只有在這兩個(gè)注解都存在的情況下,Swagger才會(huì)被正確啟用。

如果您的項(xiàng)目使用的是Swagger 3(即OpenAPI 3),則配置文件可能如下所示:

package your.package.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .select()
                .apis(RequestHandlerSelectors.basePackage("your.package.controller"))
                .paths(PathSelectors.any())
                .build();
    }
}

訪問http://localhost:8080/swagger-ui.html(假設(shè)項(xiàng)目運(yùn)行在8080端口)應(yīng)該可以看到Swagger UI。如果您的項(xiàng)目使用的是OpenAPI 3,訪問http://localhost:8080/swagger-ui/index.html。

啟動(dòng)項(xiàng)目

訪問http://localhost:8080/swagger-ui.html
swagger配置登錄密碼,spring boot,bootstrap,ui
訪問http://localhost:8080/doc.html
swagger配置登錄密碼,spring boot,bootstrap,ui

賬號(hào)密碼登錄

現(xiàn)有需求,/swagger-ui.html 頁面需要添加登錄認(rèn)證,但是本來的接口不需要登錄認(rèn)證

一、使用http://localhost:8080/swagger-ui.html路徑訪問,設(shè)置賬號(hào)密碼登錄:

為Swagger UI添加登錄權(quán)限,我使用Spring Security來實(shí)現(xiàn)。首先,確保您已經(jīng)在項(xiàng)目中添加了Spring Security依賴。在pom.xml文件中添加以下依賴:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

從application.yml文件中讀取用戶名和密碼

# 自定義swagger登錄攔截,攔截路徑swagger-ui.html和/doc.html
custom-swagger-security:
  basic:
    enabled: false
    path: /swagger-ui.html
  user:
    name: admin #賬號(hào)
    password: 123456  #密碼

接下來,創(chuàng)建一個(gè)配置類來配置Spring Security。在src/main/java/your/package/config目錄下,創(chuàng)建一個(gè)名為SecurityConfig.java的文件,并添加以下內(nèi)容:

package your.package.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${security.user.name}")
    private String username;

    @Value("${security.user.password}")
    private String password;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeRequests()
                .antMatchers(HttpMethod.GET, "/swagger-ui.html").authenticated()
                //.antMatchers(HttpMethod.GET, "/webjars/**", "/swagger-resources/**", "/v2/api-docs").permitAll()
                .anyRequest().permitAll()
            .and()
            .httpBasic();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .inMemoryAuthentication()
                .withUser(username)
                .password("{noop}" + password)
                .roles("USER");
    }
}

這個(gè)配置類繼承了WebSecurityConfigurerAdapter,并覆蓋了configure(HttpSecurity http)和configure(AuthenticationManagerBuilder auth)方法。在configure(HttpSecurity http)方法中,我們配置了對(duì)/swagger-ui.html的訪問需要認(rèn)證,同時(shí)允許訪問其他必要的資源。

在configure(AuthenticationManagerBuilder auth)方法中,我們?cè)O(shè)置了一個(gè)內(nèi)存中的用戶(admin)和密碼(123456)。這里我們使用了明文密碼,但在實(shí)際生產(chǎn)環(huán)境中,請(qǐng)確保使用加密的密碼。

在Spring Security 5中,可以使用"{noop}"前綴來表示不對(duì)密碼進(jìn)行加密。這將告訴Spring Security使用NoOpPasswordEncoder來處理密碼。將此前綴添加到SecurityConfig.java中的.password()方法中,可以解決 "There is no PasswordEncoder mapped for the id 'null'" 錯(cuò)誤。

請(qǐng)注意,這種方法不建議在生產(chǎn)環(huán)境中使用,因?yàn)樗话踩?。在生產(chǎn)環(huán)境中,您應(yīng)該使用一個(gè)安全的密碼編碼器,例如 BCryptPasswordEncoder。

現(xiàn)在,當(dāng)您訪問http://localhost:8080/swagger-ui.html時(shí),瀏覽器會(huì)要求您輸入用戶名和密碼。只有在輸入正確的用戶名和密碼后,您才能訪問Swagger UI。
swagger配置登錄密碼,spring boot,bootstrap,ui

二、使用http://localhost:8080/doc.html路徑訪問,設(shè)置賬號(hào)密碼登錄:

knife4j相比swagger-ui更加強(qiáng)大,針對(duì)Swagger的資源接口,Knife4j提供了簡(jiǎn)單的Basic認(rèn)證功能,個(gè)人覺得文檔頁面樣式也更加簡(jiǎn)潔明了
1、yml中添加配置

knife4j:
  # 開啟增強(qiáng)配置 
  enable: true
  # 開啟生產(chǎn)環(huán)境屏蔽,配置此屬性為true,所有資源都會(huì)屏蔽輸出.
  production: false
 # 開啟Swagger的Basic認(rèn)證功能,默認(rèn)是false
  basic:
      enable: true
      # Basic認(rèn)證用戶名
      username: admin
      # Basic認(rèn)證密碼
      password: 123456

2、在swagger-ui基礎(chǔ)上只是多了@EnableSwaggerBootstrapUi類注解

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUi
public class SwaggerConfig implements WebMvcConfigurer {
	
}

訪問效果:
swagger配置登錄密碼,spring boot,bootstrap,ui

注意

knife4j:
  # 開啟增強(qiáng)配置 
  enable: true
 # 開啟生產(chǎn)環(huán)境屏蔽
  production: true

配置此屬性后,所有資源都會(huì)屏蔽輸出.

效果圖如下:
swagger配置登錄密碼,spring boot,bootstrap,ui

調(diào)整

由于http://localhost:8080/swagger-ui.htm和http://localhost:8080/doc.htm都需要登錄配置。
為了做統(tǒng)一權(quán)限驗(yàn)證,所以此處實(shí)現(xiàn)方法如下:
1、yml中配置如下

# 自定義swagger登錄攔截,攔截路徑swagger-ui.html和/doc.html
custom-swagger-security:
  basic:
    enabled: false
    path: /swagger-ui.html
  user:
    name: admin #賬號(hào)
    password: 123456  #密碼

修改

package your.package.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Security配置攔截
 * 1、開啟swagger-ui.html原生頁面認(rèn)證
 * @author chenp
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Value("${custom-swagger-security.basic.enabled:false}")
    private boolean basicEnabled;

    @Value("${custom-swagger-security.basic.path}")
    private String basicPath;

    @Value("${custom-swagger-security.user.name}")
    private String username;

    @Value("${custom-swagger-security.user.password}")
    private String password;

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable(); // Disable CSRF protection for simplicity

        if (basicEnabled) {
            http.authorizeRequests()
                    // swagger頁面需要添加登錄校驗(yàn)
                    .antMatchers(HttpMethod.GET, "/swagger-ui.html", "/doc.html").authenticated() // Require authentication for Swagger UI
                    //其他請(qǐng)求全部允許
                    .anyRequest().permitAll() // Allow all other requests
                    .and()
                    .httpBasic(); // Enable basic authentication
        } else {
            http.authorizeRequests()
                    .anyRequest().permitAll();
        }
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
                .withUser(username)
                // Use clear text password for simplicity, but don't use it in production
                //.password("{noop}" + password)
                //{noop}是使用明文密碼,不進(jìn)行加密,不建議使用在生產(chǎn)環(huán)境,在生產(chǎn)環(huán)境中,使用一個(gè)安全的密碼編碼器,例如 BCryptPasswordEncoder
                .password(passwordEncoder().encode(password))
                .roles("USER");
    }
}

ps:此處對(duì){noop}密碼編碼器改為使用一個(gè)安全的密碼編碼器,例如 BCryptPasswordEncoder

加強(qiáng)版swagger-bootstrap-ui配置

swagger-bootstrap-ui相比swagger-ui更加強(qiáng)大,提供測(cè)試及賬號(hào)密碼驗(yàn)證登錄等配置,個(gè)人覺得文檔頁面樣式更加簡(jiǎn)潔明了
配置方式基本與swagger-ui一致
1、pom依賴

<!--swagger-->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>com.github.xiaoymin</groupId>
    <artifactId>swagger-bootstrap-ui</artifactId>
    <version>1.9.6</version>
</dependency>

2、添加配置類SwaggerConfig:在swagger-ui基礎(chǔ)上只是多了@EnableSwaggerBootstrapUI類注解

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.XXX.web.controller"))//掃描包范圍
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * API 說明,包含作者、簡(jiǎn)介、版本、host、服務(wù)URL
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("XXXAPI文檔")
                .description("XXXAPI文檔")
                //.contact(new Contact("API文檔", "http://www.XXX.com/", "xxx@qq.com"))//作者信息
                //.version("1.0")//定義api 版本號(hào)
                .build();
    }
}

:如果有登錄驗(yàn)證等攔截器,如下資源需要放行

@Component
public class MyInterceptorConfigure extends WebMvcConfigurationSupport { //WebMvcConfigurer

    @Autowired
    private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // excludePathPatterns 用戶排除攔截
        String[] excludePathPatterns = { "/swagger-ui.html/**","/swagger-resources/**","/webjars/**","/v2/**"};
		registry.addInterceptor(userTokenInterceptor).addPathPatterns("/**").excludePathPatterns(excludePathPatterns);
        super.addInterceptors(registry);
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
  }

3:yml配置文件添加接口文檔訪問自定義賬號(hào)密碼

#配置swagger登陸驗(yàn)證
swagger:
  production: false
  basic:
    enable: true
    username: admin
    password: 123456

4、修改攔截器等放行資源
主要修改:

String[] excludePathPatterns = { "/doc.html/**","/swagger-resources/**","/webjars/**","/v2/**"};
@Component
public class MyInterceptorConfigure extends WebMvcConfigurationSupport { //WebMvcConfigurer

    @Autowired
    private MyInterceptor myInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // excludePathPatterns 用戶排除攔截
        String[] excludePathPatterns = { "/doc.html/**","/swagger-resources/**","/webjars/**","/v2/**"};
		registry.addInterceptor(userTokenInterceptor).addPathPatterns("/**").excludePathPatterns(excludePathPatterns);
        super.addInterceptors(registry);
    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
  }

訪問地址

localhost:8080/doc.html

資源參考
https://doc.xiaominfo.com/docs/features/accesscontrol
swagger配置及升級(jí)版swagger-bootstrap-ui配置+訪問賬號(hào)密碼登錄限制
直接使用security.basic.path無效|——springboot2.0以上的security的配置
SpringBoot - 集成Swagger、Knif4j接口文檔以及文檔添加賬號(hào)密碼登錄
Swagger設(shè)置密碼登錄
Spring Boot整合Swagger3.0及Knife4j文章來源地址http://www.zghlxwxcb.cn/news/detail-716315.html

到了這里,關(guān)于SpringBoot - 集成Swagger2、Knife4j接口文檔/升級(jí)版swagger-bootstrap-ui配置以及賬號(hào)密碼登錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • 【SpringBoot】Swagger和knife4j的使用

    【SpringBoot】Swagger和knife4j的使用

    springboot筆記集合: springboot筆記合計(jì) 沒用的廢話理論不多說,會(huì)用就完了 Swagger 是一種開源的API描述語言,就是描述API的, 同時(shí)Swagger還提供了一組工具(也叫Swagger),可以幫助開發(fā)人員自動(dòng)生成API文檔、測(cè)試API并與其他系統(tǒng)集成。 Knife4j是基于Swagge語言延伸的另一組api工具,簡(jiǎn)

    2024年02月10日
    瀏覽(20)
  • springBoo3.0集成knife4j4.1.0(swagger3)

    springBoo3.0集成knife4j4.1.0(swagger3)

    溫馨提示: springBoot 版本 3.0+ knife4j 版本 4.1.0 ?添加依賴:knife4j包含了swagger,openapi3中的依賴,所以加這一個(gè)就行。 yml文件中配置: 然后,就可以啟動(dòng)測(cè)試輸入地址http://ip:port/doc.html ?注解的基本使用可以看下這里:swagger3注解和swagger2的區(qū)別 ?這里主要提下請(qǐng)求參數(shù)為文件

    2024年02月05日
    瀏覽(23)
  • 【swagger】spring security中 swagger和knife4j集成 無法訪問 返回結(jié)果沒有內(nèi)容

    【swagger】spring security中 swagger和knife4j集成 無法訪問 返回結(jié)果沒有內(nèi)容

    作為一個(gè)強(qiáng)迫癥重度的程序猿 不想多導(dǎo)一個(gè)jar包 本文創(chuàng)作背景是鑒于網(wǎng)上大多數(shù)是舊版本swagger2的教程,且沒有針對(duì)2和3區(qū)別描述,話不多說 直接步入正題。 如果只需要knife4j文檔 導(dǎo)這 一個(gè)包 就夠了 這里以3.0+版本舉例 (對(duì)springboot比較熟悉的同學(xué)應(yīng)該清楚 starter目的就是將其

    2024年02月06日
    瀏覽(20)
  • Spring Boot 集成 API 文檔 - Swagger、Knife4J、Smart-Doc

    Spring Boot 集成 API 文檔 - Swagger、Knife4J、Smart-Doc

    Swagger 作為 API 設(shè)計(jì)和文檔的強(qiáng)大工具,是一個(gè)由專門的工具集合支持的框架,它在整個(gè) API 的生命周期中發(fā)揮作用,從設(shè)計(jì)和文檔,到測(cè)試和部署。通過提供可視化界面,Swagger 讓開發(fā)人員和最終用戶都能清晰地理解和操作 API。 使用建議:筆者建議優(yōu)先考慮 Knife4J,它已經(jīng)能

    2024年01月22日
    瀏覽(22)
  • springboot集成knife4j詳細(xì)教程

    springboot集成knife4j詳細(xì)教程

    使用原生的swagger作為接口文檔,功能不夠強(qiáng)大,并且默認(rèn)的ui比較簡(jiǎn)陋,不符合大眾審美。所以實(shí)際開發(fā)中推薦使用knife4j對(duì)swagger進(jìn)行增強(qiáng)。knife4j的地址:https://gitee.com/xiaoym/knife4j 想要使用knife4j非常簡(jiǎn)單,只要在Springboot項(xiàng)目中引入knife4j的依賴即可 注意:引入knife4j后會(huì)自動(dòng)

    2024年02月20日
    瀏覽(22)
  • SpringBoot3中Swagger整合knife4j和springdoc的配置說明

    ? springboot3開始javax包改成了jakarta,而swagger-oas等包中依然使用的是javax所以報(bào)錯(cuò)。另外springfox已經(jīng)過時(shí)了,兩年沒更新了,并且不支持OpenAPI3 標(biāo)準(zhǔn),而SpringBoot3只支持OpenAPI3規(guī)范,所以要遷移到springdoc Knife4J是一款基于Swagger快速生成API文檔和調(diào)試平臺(tái)的開源工具,它可以輕松地

    2024年02月04日
    瀏覽(33)
  • Spring Cloud Gateway集成聚合型Spring Boot API發(fā)布組件knife4j,增強(qiáng)Swagger

    Spring Cloud Gateway集成聚合型Spring Boot API發(fā)布組件knife4j,增強(qiáng)Swagger

    大家都知道,在前后端分離開發(fā)的時(shí)代,前后端接口對(duì)接是一項(xiàng)必不可少的工作。 可是, 作 為后端開發(fā),怎么和前端更好的配合,才能讓自己不心累、腦累 ,直接扔給前端一個(gè)后端開放api接口文檔或者頁面,讓前端不用看著難受,也不用前端老問你,來愉快的合作呢? 原

    2024年04月22日
    瀏覽(23)
  • springboot配置swagger/knife4j時(shí)出現(xiàn)的Unresolvable class definition for class …異常

    springboot配置swagger/knife4j時(shí)出現(xiàn)的Unresolvable class definition for class …異常

    抽取出其中的關(guān)鍵原因描述: nested exception is java.lang.IllegalArgumentException: Unresolvable class definition for class [springfox.documentation.spring.web.OnServletBasedWebApplication] springfox.documentation.common.ClassPresentInClassPathCondition 進(jìn)行原因排查后,發(fā)現(xiàn)是依賴之間版本問題的沖突導(dǎo)致,下面提供一個(gè)能

    2024年02月12日
    瀏覽(22)
  • 【超詳細(xì)】springboot + springdoc-openapi + knife4j 集成案例

    【超詳細(xì)】springboot + springdoc-openapi + knife4j 集成案例

    springdoc-openapijava庫(kù)有助于使用 spring boot 項(xiàng)目自動(dòng)生成 API 文檔。 springdoc-openapi通過在運(yùn)行時(shí)檢查應(yīng)用程序以根據(jù) spring 配置、類結(jié)構(gòu)和各種注釋推斷 API 語義來工作。 自動(dòng)生成 JSON/YAML 和 HTML 格式 API 的文檔??梢允褂?swagger-api 注釋通過注釋來完成此文檔。 該庫(kù)支持: OpenAP

    2023年04月25日
    瀏覽(30)
  • Springboot3.0.0+集成SpringDoc并配置knife4j的UI

    環(huán)境:JDK17,Springboot3+,springdoc2+,knife4j 4+ Springdoc本身也是集成了Swagger3,而knife4j美化了Swagger3的UI Knife4j官網(wǎng): 快速開始 | Knife4j Springdoc官網(wǎng) OpenAPI 3 Library for spring-boot 由于此knife4j內(nèi)依賴了SpringDoc,因此不用另外引入springdoc的依賴 springdoc依賴(無需引入),親測(cè)引入也不會(huì)沖突

    2024年02月09日
    瀏覽(30)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包