欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot2.6.7集成springfox3.0.0的示例代碼

 更新時(shí)間:2024年04月29日 09:21:48   作者:阿湯哥  
這篇文章主要介紹了springboot2.6.7集成springfox3.0.0的示例代碼,本文通過示例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧

springboot2.6.7集成springfox3.0.0 

1. pom配置

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>3.0.0</version>
</dependency>

2. 增加swagger自動(dòng)配置類

import org.springframework.context.annotation.Configuration;
import springfox.documentation.oas.annotations.EnableOpenApi;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.controller"))
                .build();
    }
	private SecurityScheme apiKey() {
        return new ApiKey("JWT", "Authorization", "header");
    }
}

此時(shí)嘗試啟動(dòng)應(yīng)用會(huì)提示一下錯(cuò)誤:

Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException

Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
        at java.lang.Iterable.forEach(Iterable.java:75)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:155)
        at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
        ... 44 more
    Caused by: java.lang.NullPointerException
        at springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56)
        at springfox.documentation.RequestHandler.sortedPaths(RequestHandler.java:113)
        at springfox.documentation.spi.service.contexts.Orderings.lambda$byPatternsCondition$3(Orderings.java:89)
        at java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:469)
        at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
        at java.util.TimSort.sort(TimSort.java:234)
        at java.util.Arrays.sort(Arrays.java:1512)
        at java.util.ArrayList.sort(ArrayList.java:1464)
        at java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:387)
        at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
        at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
        at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
        at java.util.stream.Sink$ChainedReference.end(Sink.java:258)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:483)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
        at springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider.requestHandlers(WebMvcRequestHandlerProvider.java:81)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
        at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
        at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.withDefaults(AbstractDocumentationPluginsBootstrapper.java:107)
        at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.buildContext(AbstractDocumentationPluginsBootstrapper.java:91)
        at springfox.documentation.spring.web.plugins.AbstractDocumentationPluginsBootstrapper.bootstrapDocumentationPlugins(AbstractDocumentationPluginsBootstrapper.java:82)
        at springfox.documentation.spring.web.plugins.DocumentationPluginsBootstrapper.start(DocumentationPluginsBootstrapper.java:100)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:178)
        ... 61 more

3. 配置修改

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

4. 自動(dòng)配置類增加以下內(nèi)容

@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));
}

參考

Spring Boot 2.6.0 / Spring fox 3 - Failed to start bean ‘documentationPluginsBootstrapper

到此這篇關(guān)于springboot2.6.7集成springfox3.0.0的文章就介紹到這了,更多相關(guān)springboot集成springfox3.0.0內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • IDEA創(chuàng)建web項(xiàng)目出現(xiàn)404錯(cuò)誤解決方法

    IDEA創(chuàng)建web項(xiàng)目出現(xiàn)404錯(cuò)誤解決方法

    今天先來搭建一個(gè)web工程,工程搭建好運(yùn)行時(shí)發(fā)現(xiàn)404,本文主要介紹了IDEA創(chuàng)建web項(xiàng)目出現(xiàn)404錯(cuò)誤解決方法,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-09-09
  • Spring+Http請(qǐng)求+HttpClient實(shí)現(xiàn)傳參

    Spring+Http請(qǐng)求+HttpClient實(shí)現(xiàn)傳參

    這篇文章主要介紹了Spring+Http請(qǐng)求+HttpClient實(shí)現(xiàn)傳參,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Java中的2種集合排序方法介紹

    Java中的2種集合排序方法介紹

    這篇文章主要介紹了Java中的2種集合排序方法介紹,本文直接給出代碼,相關(guān)說明請(qǐng)看代碼中的注釋,需要的朋友可以參考下
    2014-10-10
  • Spring?Boot?集成?Quartz并使用Cron?表達(dá)式實(shí)現(xiàn)定時(shí)任務(wù)

    Spring?Boot?集成?Quartz并使用Cron?表達(dá)式實(shí)現(xiàn)定時(shí)任務(wù)

    本篇文章介紹了如何在?Spring?Boot?中集成?Quartz?進(jìn)行定時(shí)任務(wù)調(diào)度,并通過?Cron?表達(dá)式?控制任務(wù)執(zhí)行時(shí)間,Quartz?提供了更強(qiáng)大的任務(wù)調(diào)度能力,比?@Scheduled?注解更靈活,適用于復(fù)雜的定時(shí)任務(wù)需求
    2025-04-04
  • Spring Security Oauth2.0 實(shí)現(xiàn)短信驗(yàn)證碼登錄示例

    Spring Security Oauth2.0 實(shí)現(xiàn)短信驗(yàn)證碼登錄示例

    本篇文章主要介紹了Spring Security Oauth2.0 實(shí)現(xiàn)短信驗(yàn)證碼登錄示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • springboot的切面應(yīng)用方式(注解Aspect)

    springboot的切面應(yīng)用方式(注解Aspect)

    文章總結(jié):Spring?Boot提供了三種攔截器:Filter、Interceptor和Aspect,Filter主要用于內(nèi)容過濾和非登錄狀態(tài)的非法請(qǐng)求過濾,無法獲取Spring框架相關(guān)的信息,Interceptor可以在獲取請(qǐng)求類名、方法名的同時(shí),獲取請(qǐng)求參數(shù),但無法獲取參數(shù)值
    2024-11-11
  • JAVA 內(nèi)部類詳解及實(shí)例

    JAVA 內(nèi)部類詳解及實(shí)例

    這篇文章主要介紹了JAVA 內(nèi)部類詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • idea web項(xiàng)目沒有小藍(lán)點(diǎn)的的兩種解決方法

    idea web項(xiàng)目沒有小藍(lán)點(diǎn)的的兩種解決方法

    本文主要介紹了idea web項(xiàng)目沒有小藍(lán)點(diǎn)的的兩種解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-07-07
  • java使用itext導(dǎo)出PDF文本絕對(duì)定位(實(shí)現(xiàn)方法)

    java使用itext導(dǎo)出PDF文本絕對(duì)定位(實(shí)現(xiàn)方法)

    下面小編就為大家?guī)硪黄猨ava使用itext導(dǎo)出PDF文本絕對(duì)定位(實(shí)現(xiàn)方法)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06
  • 淺談SpringBoot資源初始化加載的幾種方式

    淺談SpringBoot資源初始化加載的幾種方式

    在平時(shí)的業(yè)務(wù)模塊開發(fā)過程中,難免會(huì)需要做一些全局的任務(wù)、緩存、線程等等的初始化工作,那么如何解決這個(gè)問題呢?本文就來介紹一下,感興趣的可以了解一下
    2021-07-07

最新評(píng)論