創建Eureka客戶端報錯:Invocation of destroy method failed on bean with name 'scopedTarget.eurekaClient':

前言

  在之前,小鹹兒已經會了如何通過創建maven工程來創建Eureka客戶端,但是接下來,小鹹兒在使用idea提供的模板創建Eureka客戶端項目時,遇到了一個新問題:

創建Eureka Discovery項目

第一步:選擇spring initializr,點擊next(下一步)
在這裏插入圖片描述
第二步:填寫項目名稱,點擊next(下一步)
在這裏插入圖片描述
第三步:選中Spring Cloud Discovery,然後選擇Eureka Discovery Client,一直點擊next(下一步)即可。當然如果你使用其他的spring cloud 組件也可以。
在這裏插入圖片描述
  當然,使用這種方式,接下來會遇到我這種問題:

問題

Invocation of destroy method failed on bean with name ‘scopedTarget.eurekaClient’: org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name ‘eurekaInstanceConfigBean’: Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

原因

  看到這麼多的英文報錯提示,是不是特別頭疼?不用擔心,這個問題的原因十分簡單,這是因爲client裏不包含Tomcat的依賴,所以Spring容器無法創建一些實例,從而導致項目無法啓動,只需在pom.xml文件中,加上web依賴即可。

解決方法

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章