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

Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.

這篇具有很好參考價(jià)值的文章主要介紹了Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

一、問題

在啟動(dòng)springcloud的gateway模塊的時(shí)候報(bào)錯(cuò)Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.

please set spring.main.web-application-type=reactive or remove spring-boot-s,springcloud,spring,java,spring boot,Powered by 金山文檔

二、問題產(chǎn)生的原因

gateway組件中的 spring-boot-starter-webflux 和 springboot作為web項(xiàng)目啟動(dòng)必不可少的 spring-boot-starter-web 出現(xiàn)沖突。

三、解決方案(任選一種就可以)

3.1 注釋pom.xml內(nèi)容

在gateway的pom文件上注釋掉spring-boot-starter-web代碼

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

3.2修改配置文件

在配置文件上加上

spring:
    main:
        web-application-type: reactive

解釋:這里面涉及到springboot的啟動(dòng)流程因?yàn)?span id="n5n3t3z" class="kdocs-bold" style="font-weight:bold;">spring-boot-starter-webflux包,在springboot啟動(dòng)類型里面表示的就是reactive。我們可以看源碼,了解一下springboot啟動(dòng)流程

一步一步點(diǎn)進(jìn)去

please set spring.main.web-application-type=reactive or remove spring-boot-s,springcloud,spring,java,spring boot,Powered by 金山文檔
please set spring.main.web-application-type=reactive or remove spring-boot-s,springcloud,spring,java,spring boot,Powered by 金山文檔

這是springApplication構(gòu)造方法,我們先看構(gòu)造方法

please set spring.main.web-application-type=reactive or remove spring-boot-s,springcloud,spring,java,spring boot,Powered by 金山文檔

點(diǎn)進(jìn)去

please set spring.main.web-application-type=reactive or remove spring-boot-s,springcloud,spring,java,spring boot,Powered by 金山文檔

3.2.1通過springboot源碼解釋

springApplication構(gòu)造源碼(不同版本會(huì)有差異,當(dāng)前版本是2.6.1)

public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
? ? ? ? 
        this.sources = new LinkedHashSet();
? ? ? ? // 在控制臺(tái)打印banner.txt文本內(nèi)容
        this.bannerMode = Mode.CONSOLE;
        this.logStartupInfo = true;
        this.addCommandLineProperties = true;
        this.addConversionService = true;
        this.headless = true;
        this.registerShutdownHook = true;
        this.additionalProfiles = Collections.emptySet();
        this.isCustomEnvironment = false;
        this.lazyInitialization = false;
        this.applicationContextFactory = ApplicationContextFactory.DEFAULT;
        this.applicationStartup = ApplicationStartup.DEFAULT;
? ? ? ? // 開始輸resourceLoader注入了屬性null
        this.resourceLoader = resourceLoader;
        Assert.notNull(primarySources, "PrimarySources must not be null");
? ? ? ? //將啟動(dòng)類從數(shù)組重新封裝Set,注入到primarySources當(dāng)中
        this.primarySources = new LinkedHashSet(Arrays.asList(primarySources));
? ? ? ? /**
? ? ? ? ? *webApplicationType有三種類型,REACTIVE,SERVLET,NONE
? ? ? ? ? *? 引入spring-boot-starter-web就是SERVLET
? ? ? ? ? *? 引入spring-boot-starter-webflux就是REACTIVE
? ? ? ? ? *? 沒有就是NONE
? ? ? ?   */
        this.webApplicationType = WebApplicationType.deduceFromClasspath();
? ? ? ? /**
? ? ? ? ? *從spring-cloud-context的jar包的META-INF/spring.factories文件中得到key為org.springfra  ? ? ? ?? *mework.boot.BootstrapRegistryInitializer的全類名集合,進(jìn)行實(shí)例化,然后注入 bootstrapRegi
? ? ? ? ? *stryInitializers 屬性,其中核心方法getSpringFactoriesInstances
? ? ? ? ? *下面有g(shù)etSpringFactoriesInstances方法源碼詳解
? ? ? ? ? *這里簡(jiǎn)單的解釋一下getSpringFactoriesInstances方法就是從META-INF/spring.factories讀取配
? ? ? ? ? *置文件? ? ? ? ? ? 
? ? ? ? ? */
        this.bootstrapRegistryInitializers = new ArrayList(this.getSpringFactoriesInstances(BootstrapRegistryInitializer.class));
? ? ? ? /**
? ? ? ? ? *依然調(diào)用getSpringFactoriesInstances方法
? ? ? ? ? *從spring-boot的jar包的META-INF/spring.factories文件中得到key為org.springframework.? ? ? ?     *context.ApplicationContextInitializer的全類名集合,然后進(jìn)行實(shí)例化,然后注入initializers
? ? ? ? ? *(初始化容器集合)屬性? 
? ? ? ? ? */
        this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class));
? ? ? ? //跟上面一樣,這里是得到監(jiān)聽器的集合,并注入
        this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class));
? ? ? ? //獲取當(dāng)前的main方法運(yùn)行的類,也就是我們的主類
        this.mainApplicationClass = this.deduceMainApplicationClass();
    }

上面說的META-INF/spring.factories都是在springboot.jar包中,不過BootstrapRegistryInitializer是在spring-cloud-context中。

3.2.2了解getSpringFactoriesInstances方法

隨便選一個(gè)點(diǎn)進(jìn)去文章來源地址http://www.zghlxwxcb.cn/news/detail-793869.html

please set spring.main.web-application-type=reactive or remove spring-boot-s,springcloud,spring,java,spring boot,Powered by 金山文檔
please set spring.main.web-application-type=reactive or remove spring-boot-s,springcloud,spring,java,spring boot,Powered by 金山文檔
  private <T> Collection<T> getSpringFactoriesInstances(Class<T> type, Class<?>[] parameterTypes, Object... args) {
        ClassLoader classLoader = this.getClassLoader();
? ? ? ? /** SpringFactoriesLoader.loadFactoryNames(type, classLoader)這里才是核心,
? ? ? ? ? *這個(gè)方法會(huì)掃描所有jar包類路徑下 META-INF/spring.factories
? ? ? ? ? */
        Set<String> names = new LinkedHashSet(SpringFactoriesLoader.loadFactoryNames(type, classLoader));
        List<T> instances = this.createSpringFactoriesInstances(type, parameterTypes, classLoader, args, names);
        AnnotationAwareOrderComparator.sort(instances);
        return instances;
    }

到了這里,關(guān)于Please set spring.main.web-application-type=reactive or remove spring-boot-starter-web dependency.的文章就介紹完了。如果您還想了解更多內(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)文章

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包