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

SpringBoot啟動(dòng)失敗的原因及其解決方法

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

前言:

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

報(bào)錯(cuò):

1:端口占用報(bào)錯(cuò)

***************************
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)聽(tīng)端口8987的Tomcat連接器啟動(dòng)失敗。端口可能已經(jīng)在使用中,或者連接器可能配置錯(cuò)誤。
 
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.
 
// 驗(yàn)證連接器的配置,識(shí)別并停止端口8987上正在運(yùn)行的任何進(jìn)程,或?qū)⒋藨?yīng)用程序配置為監(jiān)聽(tīng)另一個(gè)端口。
  • 報(bào)錯(cuò):The port may already be in use  —>  端口可能已經(jīng)在使用中
  • 原因:8987 端口被占用
  • 解決:給springboot換一個(gè)端口或關(guān)閉占用端口的程序。

2:mapper掃描類報(bào)錯(cuò)

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

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

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

如果文件是在com.ruoyi.testa.mytest.mapper中,1個(gè) * 配置依然會(huì)找不到這個(gè)Mapper文件,會(huì)報(bào)同樣的錯(cuò)誤,應(yīng)該用**,@MapperScan(value = "com.ruoyi.**.mapper")。
 

3.數(shù)據(jù)庫(kù)連接問(wèn)題

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
// 配置數(shù)據(jù)源失敗:沒(méi)有指定'url'屬性,無(wú)法配置嵌入的數(shù)據(jù)源。
 
Reason: Failed to determine a suitable driver class
// 原因:無(wú)法確定合適的驅(qū)動(dòng)程序類
 
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).
// 請(qǐng)考慮以下幾點(diǎn):
// 如果你想要嵌入式數(shù)據(jù)庫(kù)(H2、HSQL或Derby),請(qǐng)把它放在classpath(類路徑)上。
// 如果要從特定配置文件加載數(shù)據(jù)庫(kù)設(shè)置,則可能需要激活它(當(dāng)前沒(méi)有配置文件處于活動(dòng)狀態(tài))。

報(bào)錯(cuò):Failed to determine a suitable driver class  —> 沒(méi)法確定合適的驅(qū)動(dòng)程序類

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

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

# 數(shù)據(jù)源配置
spring:
    datasource:
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.mysql.cj.jdbc.Driver
        druid:
            # 主庫(kù)數(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ù)庫(kù)坐標(biāo):

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

4:沒(méi)有綁定連接池

***************************
APPLICATION FAILED TO START
***************************
 
Description:
 
Failed to bind properties under 'spring.datasource.type' to java.lang.Class<javax.sql.DataSource>:
// 沒(méi)法把'spring.datasource.type'下的屬性綁定到j(luò)ava.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
    //來(lái)源: 類路徑資源[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
// 更新應(yīng)用程序的配置

原因:沒(méi)導(dǎo)入Druid連接池的坐標(biāo),所以找不到com.alibaba.druid.pool.DruidDataSource,把Druid連接池的坐標(biāo)正確導(dǎo)入即可

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

5:無(wú)法確定合適的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ù)源失?。簺](méi)有指定“url”屬性,無(wú)法配置嵌入的數(shù)據(jù)源。
 
Reason: Failed to determine suitable jdbc url
// 原因:無(wú)法確定合適的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).
// 請(qǐng)考慮以下幾點(diǎn):
// 如果你想要嵌入式數(shù)據(jù)庫(kù)(H2、HSQL或Derby),請(qǐng)把它放在類路徑上。
// 如果要從特定配置文件加載數(shù)據(jù)庫(kù)設(shè)置,則可能需要激活它(當(dāng)前沒(méi)有激活的配置文件)。
報(bào)錯(cuò):Failed to determine suitable jdbc url  —> 無(wú)法確定合適的jdbc url
原因:

url沒(méi)有被讀取到,配置文件沒(méi)有生效,其大概原因有以下幾點(diǎn):

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

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

Description:
 
The dependencies of some of the beans in the application context form a cycle:
// 應(yīng)用程序上下文中某些bean的依賴關(guān)系形成一個(gè)循環(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)場(chǎng)景:SpringBoot中自定義DataSource數(shù)據(jù)源
  • 原因:自定義數(shù)據(jù)源一定要排除SpringBoot自動(dòng)配置數(shù)據(jù)源,不然會(huì)出現(xiàn)循環(huán)引用的問(wèn)題。
  • 解決:排除Spring Boot數(shù)據(jù)源自動(dòng)配置類
@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,無(wú)法啟動(dòng)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 且隨疾風(fēng)前行 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

報(bào)錯(cuò):Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean. (由于缺少ServletWebServerFactory bean,無(wú)法啟動(dòng)ServletWebServerApplicationContext)

解決:?jiǎn)?dòng)類添加@EnableAutoConfiguration注解即可解決問(wèn)題

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
  • 報(bào)錯(cuò):An attempt was made to call a method that does not exist.(試圖調(diào)用不存在的方法。)
  • 原因:依賴沖突
  • 解決:
  • 1.先重新編譯運(yùn)行試下

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

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

相關(guān)文章

  • Jmeter如何獲取jtl文件中所有的請(qǐng)求報(bào)文詳解

    Jmeter如何獲取jtl文件中所有的請(qǐng)求報(bào)文詳解

    JMeter的可以創(chuàng)建一個(gè)包含測(cè)試運(yùn)行結(jié)果的文本文件,這些通常稱為JTL文件,因?yàn)檫@是默認(rèn)擴(kuò)展名,但可以使用任何擴(kuò)展名,這篇文章主要給大家介紹了關(guān)于Jmeter如何獲取jtl文件中所有的請(qǐng)求報(bào)文的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • Java中和隊(duì)列相關(guān)的基本操作

    Java中和隊(duì)列相關(guān)的基本操作

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

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

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

    詳解使用Maven構(gòu)建多模塊項(xiàng)目(圖文)

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

    IDEA連接mysql數(shù)據(jù)庫(kù)報(bào)錯(cuò)的解決方法

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

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

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

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

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

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

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

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

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

    SpringBoot快速通關(guān)自動(dòng)配置應(yīng)用

    在進(jìn)行項(xiàng)目編寫前,我們還需要知道一個(gè)東西,就是SpringBoot對(duì)我們的SpringMVC還做了哪些配置,包括如何擴(kuò)展,如何定制,只有把這些都搞清楚了,我們?cè)谥笫褂貌艜?huì)更加得心應(yīng)手
    2022-07-07

最新評(píng)論