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

SpringBoot啟動失敗的原因及其解決方法

 更新時間:2024年06月27日 09:42:02   作者:沖鋒的禾  
對于springboot的啟動失敗,相信大家都有經(jīng)歷,但是為什么會啟動失敗,以及怎么解決都只能通過日志進行查看,在這里,我會將常見的springboot啟動失敗的報錯一一展示,需要的朋友可以參考下

前言:

對于springboot的啟動失敗,相信大家都有經(jīng)歷,但是為什么會啟動失敗,以及怎么解決都只能通過日志進行查看,在這里,我會將常見的springboot啟動失敗的報錯一一展示

報錯:

1:端口占用報錯

***************************
APPLICATION FAILED TO START
***************************
 
Description:
The Tomcat connector configured to listen on port 8987 failed to start. The port  may already be in use or the connector may be misconfigured.
 
// 配置為監(jiān)聽端口8987的Tomcat連接器啟動失敗。端口可能已經(jīng)在使用中,或者連接器可能配置錯誤。
 
Action:
Verify the connector's configuration, identify and stop any process that's liste ning on port 8987, or configure this application to listen on another port.
 
// 驗證連接器的配置,識別并停止端口8987上正在運行的任何進程,或?qū)⒋藨贸绦蚺渲脼楸O(jiān)聽另一個端口。
  • 報錯:The port may already be in use  —>  端口可能已經(jīng)在使用中
  • 原因:8987 端口被占用
  • 解決:給springboot換一個端口或關閉占用端口的程序。

2:mapper掃描類報錯

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Field clustersDetailsAmqMapper in com.ruoyi.clusters.service.impl.ClustersDetailsAmqServiceImpl required a bean of type 'com.ruoyi.clusters.mapper.ClustersDetailsAmqMapper' that could not be found.
 
// 在 com.ruoyi.clusters.service.impl.ClustersDetailsAmqServiceImpl 中的屬性 clustersDetailsAmqMapper 需要一個類型為'com.ruoyi.clusters.mapper.ClustersDetailsAmqMapper'的bean,但是找不到它。
 
The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)
 
// 注入點具有以下注釋:-@org.springframework.beans.factory.annotation.Autowired(必需=true)
 
Action:
 
Consider defining a bean of type 'com.ruoyi.clusters.mapper.ClustersDetailsAmqMapper' in your configuration.
 
// 考慮在配置中定義一個類型為'com.ruoyi.clusters.mapper.ClustersDetailsAmqMapper'的bean。
  • 報錯:Field xxxMapper in xxx required a bean of type 'xxxMapper' that could not be found. —> 在xxx中的屬性xxxMapper 需要一個類型為'xxxMapper'的 bean,但是找不到它。
  • 原因:springboot的啟動類 沒有配置mapper掃描路徑 或 配置的mapper文件掃描路徑不對。
  • 解決:在springboot啟動類中 配置正確的mapper文件掃描,如下:
@SpringBootApplication
@MapperScan(value = "com.ruoyi.**.mapper")  
// 路徑必須與mapper文件在的路徑一致,否則依然會報錯
public class RuoYiApplication {
    public static void main(String[] args) {
        SpringApplication.run(RuoYiApplication.class, args);
    }
}

注意:* 指的是下一級目錄,** 指的是包含其子目錄在內(nèi)的。

如果Mapper文件在com.ruoyi.testa.mapper中,用@MapperScan(value = "com.ruoyi.*.mapper") 是可以的,

如果文件是在com.ruoyi.testa.mytest.mapper中,1個 * 配置依然會找不到這個Mapper文件,會報同樣的錯誤,應該用**,@MapperScan(value = "com.ruoyi.**.mapper")。
 

3.數(shù)據(jù)庫連接問題

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
// 配置數(shù)據(jù)源失?。簺]有指定'url'屬性,無法配置嵌入的數(shù)據(jù)源。
 
Reason: Failed to determine a suitable driver class
// 原因:無法確定合適的驅(qū)動程序類
 
Action:
 
Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
// 請考慮以下幾點:
// 如果你想要嵌入式數(shù)據(jù)庫(H2、HSQL或Derby),請把它放在classpath(類路徑)上。
// 如果要從特定配置文件加載數(shù)據(jù)庫設置,則可能需要激活它(當前沒有配置文件處于活動狀態(tài))。

報錯:Failed to determine a suitable driver class  —> 沒法確定合適的驅(qū)動程序類

原因:沒有在application.yml中配置數(shù)據(jù)源(比如druid連接池)或 數(shù)據(jù)庫驅(qū)動(比如mysql)

加上數(shù)據(jù)源配置:

# 數(shù)據(jù)源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.mysql.cj.jdbc.Driver
        druid:
            # 主庫數(shù)據(jù)源
            master:
                url: jdbc:mysql://127.0.0.1:3306/car?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                username: root
                password: root

加上數(shù)據(jù)庫坐標:

 <!-- Mysql驅(qū)動包 -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

4:沒有綁定連接池

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Failed to bind properties under 'spring.datasource.type' to java.lang.Class<javax.sql.DataSource>:
// 沒法把'spring.datasource.type'下的屬性綁定到java.lang.Class<javax.sql.datasource>:
    Property: spring.datasource.type
    // 屬性:spring.datasource.type
    Value: com.alibaba.druid.pool.DruidDataSource
    // 值: com.alibaba.druid.pool.DruidDataSource
    Origin: class path resource [application-druid.yml]:4:15
    //來源: 類路徑資源[application-druid.yml]:4:15
    Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<javax.sql.DataSource>]
// 原因:找不到能夠從類型[java.lang.String]轉(zhuǎn)換為類型[java.lang.Class<javax.sql.DataSource>]的轉(zhuǎn)換器
 
Action:
 
Update your application's configuration
// 更新應用程序的配置

原因:沒導入Druid連接池的坐標,所以找不到com.alibaba.druid.pool.DruidDataSource,把Druid連接池的坐標正確導入即可

<!--阿里數(shù)據(jù)庫連接池 -->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
</dependency>

5:無法確定合適的jdbc url

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
// 配置數(shù)據(jù)源失?。簺]有指定“url”屬性,無法配置嵌入的數(shù)據(jù)源。
 
Reason: Failed to determine suitable jdbc url
// 原因:無法確定合適的jdbc url
 
Action:
 
Consider the following:
	If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
	If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
// 請考慮以下幾點:
// 如果你想要嵌入式數(shù)據(jù)庫(H2、HSQL或Derby),請把它放在類路徑上。
// 如果要從特定配置文件加載數(shù)據(jù)庫設置,則可能需要激活它(當前沒有激活的配置文件)。
報錯:Failed to determine suitable jdbc url  —> 無法確定合適的jdbc url
原因:

url沒有被讀取到,配置文件沒有生效,其大概原因有以下幾點:

系統(tǒng)編碼不正確。跑項目之前最好讓項目與文件的編碼對應起來
可能有和你所在項目平級的配置文件,springboot會優(yōu)先讀取項目同級別目錄下的配置文件
idea沒有將resource設置為資源目錄
檢查DruidConfig配置類(或配置文件)
檢查一下Application啟動文件的位置,建議將其放在外層:如果SpringBootApplication啟動文件位置在數(shù)據(jù)庫配置DruidConfig文件下層,則不會對這個Configuration進行掃描,然后去找默認的配置,所以導致Failed to determine suitable jdbc url

6:自定義數(shù)據(jù)源一定要排除SpringBoot自動配置數(shù)據(jù)源,不然會出現(xiàn)循環(huán)引用的問題

Description:
 
The dependencies of some of the beans in the application context form a cycle:
// 應用程序上下文中某些bean的依賴關系形成一個循環(huán):
 
   testAController (field private com.ruoyi.testa.service.TestAService com.ruoyi.apis.TestAController.testAService)
      ↓
   testAServiceImpl (field private com.ruoyi.testa.mapper.TestAMapper com.ruoyi.testa.service.impl.TestAServiceImpl.testAMapper)
      ↓
   testAMapper defined in file [E:\IdeaProjects2018\car\ruoyi-mapper\target\classes\com\ruoyi\testa\mapper\TestAMapper.class]
      ↓
   sqlSessionFactory defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]
┌─────┐
|  dynamicDataSource defined in class path resource [com/ruoyi/config/DruidConfig.class]
↑     ↓
|  masterDataSource defined in class path resource [com/ruoyi/config/DruidConfig.class]
↑     ↓
|  org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker
└─────┘
  • 異常出現(xiàn)場景:SpringBoot中自定義DataSource數(shù)據(jù)源
  • 原因:自定義數(shù)據(jù)源一定要排除SpringBoot自動配置數(shù)據(jù)源,不然會出現(xiàn)循環(huán)引用的問題。
  • 解決:排除Spring Boot數(shù)據(jù)源自動配置類
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@MapperScan(value = "com.ruoyi.**.mapper") 
public class RuoYiApplication {
    public static void main(String[] args) {
        SpringApplication.run(RuoYiApplication.class, args);
    }
}

7:由于缺少ServletWebServerFactory bean,無法啟動ServletWebServerApplicationContext

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.3.RELEASE)
2020-09-01 11:21:54.103  INFO 21308 --- [           main] com.smr.bluetooth.DeviceCommApplication  : Starting DeviceCommApplication on LAPTOP-RM7CN477 with PID 21308 (E:\IdeaProjects2018\bluetooth_test\target\classes started by 且隨疾風前行 in E:\IdeaProjects2018\bluetooth_test)
2020-09-01 11:21:54.106  INFO 21308 --- [           main] com.smr.bluetooth.DeviceCommApplication  : No active profile set, falling back to default profiles: default
2020-09-01 11:21:54.133  INFO 21308 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@770c2e6b: startup date [Tue Sep 01 11:21:54 CST 2020]; root of context hierarchy
2020-09-01 11:21:54.232  WARN 21308 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2020-09-01 11:21:54.605 ERROR 21308 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at com.smr.bluetooth.DeviceCommApplication.main(DeviceCommApplication.java:10) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:152) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
	... 8 common frames omitted

報錯:Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. (由于缺少ServletWebServerFactory bean,無法啟動ServletWebServerApplicationContext)

解決:啟動類添加@EnableAutoConfiguration注解即可解決問題

8:依賴沖突

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
An attempt was made to call a method that does not exist. The attempt was made from the following location:
 
org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1319)
 
The following method did not exist:
 
javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
 
The calling method's class, org.apache.catalina.authenticator.AuthenticatorBase, was loaded from the following location:
jar:file:/E:/Maven/maven-repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.63/tomcat-embed-core-9.0.63.jar!/org/apache/catalina/authenticator/AuthenticatorBase.class
The called method's class, javax.servlet.ServletContext, is available from the following locations:
 
jar:file:/E:/Maven/maven-repository/org/apache/tomcat/servlet-api/6.0.18/servlet-api-6.0.18.jar!/javax/servlet/ServletContext.class
jar:file:/E:/Maven/maven-repository/org
  • 報錯:An attempt was made to call a method that does not exist.(試圖調(diào)用不存在的方法。)
  • 原因:依賴沖突
  • 解決:
  • 1.先重新編譯運行試下

2.排查是否是版本不兼容、版本沖突等

以上就是SpringBoot啟動失敗的原因及其解決方法的詳細內(nèi)容,更多關于SpringBoot啟動失敗的資料請關注腳本之家其它相關文章!

相關文章

  • Jmeter如何獲取jtl文件中所有的請求報文詳解

    Jmeter如何獲取jtl文件中所有的請求報文詳解

    JMeter的可以創(chuàng)建一個包含測試運行結果的文本文件,這些通常稱為JTL文件,因為這是默認擴展名,但可以使用任何擴展名,這篇文章主要給大家介紹了關于Jmeter如何獲取jtl文件中所有的請求報文的相關資料,需要的朋友可以參考下
    2021-09-09
  • Java中和隊列相關的基本操作

    Java中和隊列相關的基本操作

    在Java中,隊列是一種常用的數(shù)據(jù)結構,用于存儲和管理元素。Java提供了Queue接口和其實現(xiàn)類,包括LinkedList和ArrayDeque等。隊列的基本操作包括入隊(enqueue)、出隊(dequeue)、獲取隊首元素(peek)和判斷隊列是否為空(isEmpty)。
    2023-09-09
  • Spring Jpa多數(shù)據(jù)源工程配置過程解析

    Spring Jpa多數(shù)據(jù)源工程配置過程解析

    這篇文章主要介紹了Spring Jpa多數(shù)據(jù)源工程配置過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-08-08
  • 詳解使用Maven構建多模塊項目(圖文)

    詳解使用Maven構建多模塊項目(圖文)

    這篇文章主要介紹了詳解使用Maven構建多模塊項目(圖文),非常具有實用價值,需要的朋友可以參考下
    2017-09-09
  • IDEA連接mysql數(shù)據(jù)庫報錯的解決方法

    IDEA連接mysql數(shù)據(jù)庫報錯的解決方法

    這篇文章主要介紹了IDEA連接mysql數(shù)據(jù)庫報錯的解決方法,文中有非常詳細的圖文示例,對出現(xiàn)Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ prope報錯的小伙伴們很有幫助喲,需要的朋友可以參考下
    2021-05-05
  • Java實現(xiàn)二分法變種的示例代碼

    Java實現(xiàn)二分法變種的示例代碼

    這篇文章主要為大家介紹了Java實現(xiàn)二分法變種的示例代碼復,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-11-11
  • Java如何不解壓讀取.zip的文件內(nèi)容

    Java如何不解壓讀取.zip的文件內(nèi)容

    這篇文章主要給大家介紹了關于Java如何不解壓讀取.zip的文件內(nèi)容的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • Java 詳解循環(huán)屏障CyclicBarrier如何實現(xiàn)多線程分段等待執(zhí)行完成

    Java 詳解循環(huán)屏障CyclicBarrier如何實現(xiàn)多線程分段等待執(zhí)行完成

    CyclicBarrier是一個同步工具類,可以翻譯成循環(huán)屏障,也叫障礙器或同步屏障。CyclicBarrier內(nèi)部有一個計數(shù)器count,調(diào)用障礙器的await方法會使計數(shù)器count的值減一,當計數(shù)器count的值為0時,表明調(diào)用了await方法線程已經(jīng)達到了設置的數(shù)量
    2021-11-11
  • spring mvc @PathVariable綁定URI模板變量值方式

    spring mvc @PathVariable綁定URI模板變量值方式

    這篇文章主要介紹了spring mvc @PathVariable綁定URI模板變量值方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • SpringBoot快速通關自動配置應用

    SpringBoot快速通關自動配置應用

    在進行項目編寫前,我們還需要知道一個東西,就是SpringBoot對我們的SpringMVC還做了哪些配置,包括如何擴展,如何定制,只有把這些都搞清楚了,我們在之后使用才會更加得心應手
    2022-07-07

最新評論