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

解決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ò)展,是簡化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)文章

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

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

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

    IntelliJ?IDEA教程之clean或者install?Maven項(xiàng)目的操作方法

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

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

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

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

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

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

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

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

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

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

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

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

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

    Java生產(chǎn)者和消費(fèi)者例子_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

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

    Java多線程join方法實(shí)例代碼

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

最新評(píng)論