最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

解決springboot服務(wù)啟動(dòng)報(bào)錯(cuò):Unable?to?start?embedded?contain

 更新時(shí)間:2022年08月18日 09:48:40   作者:Yeah-小海  
這篇文章主要介紹了解決springboot服務(wù)啟動(dòng)報(bào)錯(cuò):Unable?to?start?embedded?contain的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

初次接觸spring-boot + spring-cloud構(gòu)建微服務(wù)項(xiàng)目,配置好項(xiàng)目后并選擇啟動(dòng)類啟動(dòng)時(shí)報(bào)如下錯(cuò)誤:

[main] ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
    at com.dispatchCenter.main.DispatchCenterApplication.main(DispatchCenterApplication.java:9)
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:189)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134)
    ... 8 common frames omitted

1. 根據(jù)報(bào)錯(cuò)信息發(fā)現(xiàn)是在刷新容器的方法onRefresh中拋出的

為什么是刷新容器的方法呢?相信大家都知道spring-boot是基于spring的擴(kuò)展,是簡(jiǎn)化spring配置的一個(gè)工具,

至于spring是怎么初始化的在本篇不做概述。我們?cè)谶@只需要知道

EmbeddedWebApplicationContext extends org.springframework.web.context.support.GenericWebApplicationContext

下面點(diǎn)進(jìn)去查看EmbeddedWebApplicationContext此類中刷新容器的方法的源碼如下:

?? ?protected void onRefresh() {
? ? ? ? super.onRefresh(); ?--這里就是刷新spring容器的入口
?
? ? ? ? try {
? ? ? ? ? ? this.createEmbeddedServletContainer(); ? --捕獲的是這個(gè)方法中的異常
? ? ? ? } catch (Throwable var2) {
? ? ? ? ? ? throw new ApplicationContextException("Unable to start embedded container", var2); --這里捕獲異常后拋出
? ? ? ? }
? ? }

2. 接著被捕獲異常的方法源碼

private void createEmbeddedServletContainer() {
? ? ? ? EmbeddedServletContainer localContainer = this.embeddedServletContainer;
? ? ? ? ServletContext localServletContext = this.getServletContext();
? ? ? ? if (localContainer == null && localServletContext == null) {
? ? ? ? ? ? EmbeddedServletContainerFactory containerFactory = this.getEmbeddedServletContainerFactory(); ?--根據(jù)報(bào)錯(cuò)信息這里拋出的異常
? ? ? ? ? ? this.embeddedServletContainer = containerFactory.getEmbeddedServletContainer(new ServletContextInitializer[]{this.getSelfInitializer()});
? ? ? ? } else if (localServletContext != null) {
? ? ? ? ? ? try {
? ? ? ? ? ? ? ? this.getSelfInitializer().onStartup(localServletContext);
? ? ? ? ? ? } catch (ServletException var4) {
? ? ? ? ? ? ? ? throw new ApplicationContextException("Cannot initialize servlet context", var4);
? ? ? ? ? ? }
? ? ? ? }
?
? ? ? ? this.initPropertySources();
? ? }

3. 再接著就是拋出異常的根源所在的源碼

通過查看源碼得出是啟動(dòng)時(shí)從beanFactory中找不到所需bean的存在,也就是bean根本沒有注冊(cè):

protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() {
? ? ? ? String[] beanNames = this.getBeanFactory().getBeanNamesForType(EmbeddedServletContainerFactory.class); --這里通過類型去查詢bean,結(jié)果發(fā)現(xiàn)一個(gè)都沒有就拋出異常了,當(dāng)然如果超過一個(gè)也會(huì)拋出異常
? ? ? ? if (beanNames.length == 0) {
? ? ? ? ? ? throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.");
? ? ? ? } else if (beanNames.length > 1) {
? ? ? ? ? ? throw new ApplicationContextException("Unable to start EmbeddedWebApplicationContext due to multiple EmbeddedServletContainerFactory beans : " + StringUtils.arrayToCommaDelimitedString(beanNames));
? ? ? ? } else {
? ? ? ? ? ? return (EmbeddedServletContainerFactory)this.getBeanFactory().getBean(beanNames[0], EmbeddedServletContainerFactory.class);
? ? ? ? }
? ? }

4. 知道原因了反過去查看代碼發(fā)現(xiàn)啟動(dòng)類中少寫了注解

太粗心大意了

@EnableEurekaServer
@SpringBootApplication

5. 還有一種情況需要注意

我們使用注解標(biāo)注了這個(gè)啟動(dòng)類,但是還是提示Cannot resolve symbol *等問題,一定要去檢查引包是否正確

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • springboot項(xiàng)目不同環(huán)境的配置讀取方式

    springboot項(xiàng)目不同環(huán)境的配置讀取方式

    SpringBoot支持application.properties、application.yml、application.yaml三種配置文件類型,可同時(shí)存在并合并配置,配置文件的讀取優(yōu)先級(jí)為:application.properties > application.yml > application.yaml,不同位置的相同類型配置文件
    2024-11-11
  • JavaGUI實(shí)現(xiàn)隨機(jī)單詞答題游戲

    JavaGUI實(shí)現(xiàn)隨機(jī)單詞答題游戲

    這篇文章主要為大家詳細(xì)介紹了JavaGUI實(shí)現(xiàn)隨機(jī)單詞答題游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • JAVA設(shè)計(jì)模式零基礎(chǔ)解析之單例模式的八種方式

    JAVA設(shè)計(jì)模式零基礎(chǔ)解析之單例模式的八種方式

    設(shè)計(jì)模式(Design pattern)是一套被反復(fù)使用、多數(shù)人知曉的、經(jīng)過分類編目的、代碼設(shè)計(jì)經(jīng)驗(yàn)的總結(jié)。使用設(shè)計(jì)模式是為了可重用代碼、讓代碼更容易被他人理解、保證代碼可靠性
    2021-10-10
  • 解決Eclipse打開.java文件異常,提示用系統(tǒng)工具打開的問題

    解決Eclipse打開.java文件異常,提示用系統(tǒng)工具打開的問題

    這篇文章主要介紹了解決Eclipse打開.java文件異常,提示用系統(tǒng)工具打開的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • Springboot中使用Redis實(shí)現(xiàn)分布式鎖的示例代碼

    Springboot中使用Redis實(shí)現(xiàn)分布式鎖的示例代碼

    在分布式系統(tǒng)中,為了保證數(shù)據(jù)的一致性和任務(wù)的互斥執(zhí)行,分布式鎖是一種常見的解決方案,本文主要介紹了Springboot中使用Redis實(shí)現(xiàn)分布式鎖的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-05-05
  • springboot Controller直接返回String類型帶來的亂碼問題及解決

    springboot Controller直接返回String類型帶來的亂碼問題及解決

    文章介紹了在Spring Boot中,當(dāng)Controller直接返回String類型時(shí)可能出現(xiàn)的亂碼問題,并提供了解決辦法,通過在`application.yaml`中設(shè)置請(qǐng)求和響應(yīng)的編碼格式,并在自定義配置類中進(jìn)行配置,可以有效解決這一問題
    2024-11-11
  • Java8中StringJoiner類的使用詳解

    Java8中StringJoiner類的使用詳解

    Java在java.util包中添加了一個(gè)新的最終類StringJoiner。可以用于構(gòu)造由定界符分隔的字符序列。本文將通過示例和大家分享一下StringJoiner類的使用,需要的可以參考一下
    2022-10-10
  • Spring boot + thymeleaf 后端直接給onclick函數(shù)賦值的實(shí)現(xiàn)代碼

    Spring boot + thymeleaf 后端直接給onclick函數(shù)賦值的實(shí)現(xiàn)代碼

    這篇文章主要介紹了Spring boot + thymeleaf 后端直接給onclick函數(shù)賦值的實(shí)現(xiàn)代碼,需要的朋友可以參考下
    2017-06-06
  • java 解壓與壓縮文件夾的實(shí)例詳解

    java 解壓與壓縮文件夾的實(shí)例詳解

    這篇文章主要介紹了 java 解壓與壓縮文件夾的實(shí)例詳解的相關(guān)資料,希望通過本文能幫助到大家,讓大家實(shí)現(xiàn)這樣的功能,掌握這樣的方法,需要的朋友可以參考下
    2017-10-10
  • Spring Boot中自動(dòng)化配置的利弊以及解決方法

    Spring Boot中自動(dòng)化配置的利弊以及解決方法

    這篇文章主要給大家介紹了關(guān)于Spring Boot中自動(dòng)化配置的利弊以及解決方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-08-08

最新評(píng)論

武功县| 泗水县| 交城县| 尖扎县| 澄江县| 赫章县| 崇信县| 尚志市| 邵阳县| 武胜县| 孟州市| 苍溪县| 绵竹市| 南乐县| 通榆县| 迁安市| 白银市| 三原县| 临清市| 长宁区| 七台河市| 灯塔市| 体育| 广平县| 凤冈县| 乐安县| 武义县| 彰化县| 舟山市| 资阳市| 右玉县| 渝北区| 拉孜县| 呼玛县| 九龙坡区| 崇礼县| 安乡县| 八宿县| 栾城县| 龙岩市| 济宁市|