亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決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的擴展,是簡化spring配置的一個工具,

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

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

下面點進去查看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)文章

  • 深入淺出講解Java比較器及數(shù)學(xué)常用類

    深入淺出講解Java比較器及數(shù)學(xué)常用類

    這篇文章主要介紹了深入淺出講解Java比較器及數(shù)學(xué)常用類,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-09-09
  • IntelliJ?IDEA教程之clean或者install?Maven項目的操作方法

    IntelliJ?IDEA教程之clean或者install?Maven項目的操作方法

    這篇文章主要介紹了IntelliJ?IDEA教程之clean或者install?Maven項目的操作方法,本文分步驟給大家介紹兩種方式講解如何調(diào)試出窗口,需要的朋友可以參考下
    2023-04-04
  • Java進階學(xué)習(xí):jar打包詳解

    Java進階學(xué)習(xí):jar打包詳解

    Java進階學(xué)習(xí):jar打包詳解...
    2006-12-12
  • SpringBoot實現(xiàn)轉(zhuǎn)頁功能

    SpringBoot實現(xiàn)轉(zhuǎn)頁功能

    這篇文章主要介紹了SpringBoot實現(xiàn)轉(zhuǎn)頁功能,頁面的跳轉(zhuǎn)在web開發(fā)中是經(jīng)常用的基礎(chǔ)功能,感興趣想要詳細了解可以閱讀下文,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值
    2023-05-05
  • 比較Java數(shù)組和各種List的性能小結(jié)

    比較Java數(shù)組和各種List的性能小結(jié)

    這篇文章主要是分別對Java數(shù)組、ArrayList、LinkedList和Vector進行隨機訪問和迭代等操作,并比較這種集合的性能。有需要的可以參考借鑒。
    2016-08-08
  • Java創(chuàng)建子線程的兩種方法

    Java創(chuàng)建子線程的兩種方法

    這篇文章主要介紹了Java創(chuàng)建子線程的兩種方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • SpringBoot3集成和使用Jasypt的代碼詳解

    SpringBoot3集成和使用Jasypt的代碼詳解

    隨著信息安全的日益受到重視,加密敏感數(shù)據(jù)在應(yīng)用程序中變得越來越重要,Jasypt作為一個簡化Java應(yīng)用程序中數(shù)據(jù)加密的工具,為開發(fā)者提供了一種便捷而靈活的加密解決方案,本文將深入解析Jasypt的工作原理,需要的朋友可以參考下
    2024-01-01
  • Java設(shè)計模式之單例模式Singleton Pattern詳解

    Java設(shè)計模式之單例模式Singleton Pattern詳解

    這篇文章主要介紹了Java設(shè)計模式之單例模式Singleton Pattern詳解,一些常用的工具類、線程池、緩存,數(shù)據(jù)庫,數(shù)據(jù)庫連接池、賬戶登錄系統(tǒng)、配置文件等程序中可能只允許我們創(chuàng)建一個對象,這就需要單例模式,需要的朋友可以參考下
    2023-12-12
  • Java生產(chǎn)者和消費者例子_動力節(jié)點Java學(xué)院整理

    Java生產(chǎn)者和消費者例子_動力節(jié)點Java學(xué)院整理

    生產(chǎn)者-消費者(producer-consumer)問題,也稱作有界緩沖區(qū)(bounded-buffer)問題,兩個進程共享一個公共的固定大小的緩沖區(qū)。下文通過實例給大家介紹java生產(chǎn)者和消費者,感興趣的朋友一起學(xué)習(xí)吧
    2017-05-05
  • Java多線程join方法實例代碼

    Java多線程join方法實例代碼

    這篇文章主要介紹了Java多線程join方法實例代碼,分享了相關(guān)代碼示例,小編覺得還是挺不錯的,具有一定借鑒價值,需要的朋友可以參考下
    2018-02-02

最新評論