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

解決springboot服務(wù)啟動報錯:Unable?to?start?embedded?contain

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

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

[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ù)報錯信息發(fā)現(xiàn)是在刷新容器的方法onRefresh中拋出的

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

至于spring是怎么初始化的在本篇不做概述。我們在這只需要知道

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

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

?? ?protected void onRefresh() {
? ? ? ? super.onRefresh(); ?--這里就是刷新spring容器的入口
?
? ? ? ? try {
? ? ? ? ? ? this.createEmbeddedServletContainer(); ? --捕獲的是這個方法中的異常
? ? ? ? } 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ù)報錯信息這里拋出的異常
? ? ? ? ? ? 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. 再接著就是拋出異常的根源所在的源碼

通過查看源碼得出是啟動時從beanFactory中找不到所需bean的存在,也就是bean根本沒有注冊:

protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() {
? ? ? ? String[] beanNames = this.getBeanFactory().getBeanNamesForType(EmbeddedServletContainerFactory.class); --這里通過類型去查詢bean,結(jié)果發(fā)現(xiàn)一個都沒有就拋出異常了,當(dāng)然如果超過一個也會拋出異常
? ? ? ? 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)啟動類中少寫了注解

太粗心大意了

@EnableEurekaServer
@SpringBootApplication

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

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

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

相關(guān)文章

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

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

    SpringBoot支持application.properties、application.yml、application.yaml三種配置文件類型,可同時存在并合并配置,配置文件的讀取優(yōu)先級為: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ì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-12-12
  • JAVA設(shè)計模式零基礎(chǔ)解析之單例模式的八種方式

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

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

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

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

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

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

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

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

    Java8中StringJoiner類的使用詳解

    Java在java.util包中添加了一個新的最終類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中自動化配置的利弊以及解決方法

    Spring Boot中自動化配置的利弊以及解決方法

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

最新評論

康乐县| 廊坊市| 临潭县| 安化县| 湖州市| 宜昌市| 古丈县| 信丰县| 普兰店市| 江津市| 桃源县| 信丰县| 临泉县| 辽阳县| 陵水| 澄江县| 昂仁县| 无为县| 田林县| 惠安县| 江达县| 株洲县| 永寿县| 仪征市| 临桂县| 通化县| 凌云县| 林芝县| 乡城县| 怀安县| 马公市| 阳原县| 新平| 观塘区| 宜兴市| 讷河市| 栾川县| 光山县| 漯河市| 前郭尔| 西林县|