zoukankan      html  css  js  c++  java
  • 关于idea中SpringBoot启动失败的坑

    很多时候你新建了Maven 或者SpringBoot 工程,激动的点了主启动类,你就发现了下面的错误

     Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: 
    Error creating bean with name 'servletEndpointRegistrar' defined in class path resource
    [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$
    WebMvcServletEndpointManagementContextConfiguration.class]:
    Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
    Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]:
    Factory method 'servletEndpointRegistrar' threw exception;
    nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'healthEndpoint' defined in class path resource
    [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]:
    Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0;
    nested exception is org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'healthContributorRegistry' defined in class path resource
    [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]:
    Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
    Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]:
    Factory method 'healthContributorRegistry' threw exception;
    nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration':
    Unsatisfied dependency expressed through constructor parameter 0;
    nested exception is org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]:
    Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]:
    Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:
    Failed to determine a suitable driver class [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
    org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException:
    Unable to start embedded Tomcat --- [ restartedMain] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2020-09-03 13:12:04.338 ERROR 24572 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver class 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).

      这里说的是啥意思呢,你没有数据库相关的链接,数据库相关的链接在哪里配置呢,就是在你的Resource文件目录下的properties 或者yml文件中

    但是这里你可能会说,我**不用数据库,我干啥配这个b玩意,我想说这句话的时候,你已经点了很多遍的主启动都报这个错误,

    今天你算来对了,我敢肯定80%的人都遇到过这个问题。但是不知道为啥,今天我给你分析一下昂:

    ①:在IDEA 中用SpringInitial  点点点生成的SpringBoot/cloud项目
    ②:跟视频操作,一顿操作后发现不能启动,
    ③:DonwLoad下的代码   复制进去的POM依赖

    还有很多昂,不墨迹了说重点吧。
    解决方法:

    首先着重看自己的POM依赖(是自己的POM,不是父工程,也不是其他工程,是自己的)中有无以下依赖

    <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
    </dependency>
    

      

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    

      经过鄙人的测试,就是第一个依赖捣的鬼,这就是为啥你加了这个依赖你不配置相关的mysql链接,Spring就给你报错的原因。

    最后提醒:按需注入POM才是正道,老铁们,我做的对么?

    新鲜刺激的东西永远都有,玩之前掂量掂量自己几斤几两
  • 相关阅读:
    Qt: 自动调整到最合适的大小(不是很明白)
    Qt: 读写二进制文件(写对象, 原始数据等)
    Qt: 把内容写进字符串中与C++很相似(使用QTextStream包装QString)
    2008技术内幕:T-SQL语言基础
    bootstrap + angularjs + seajs构建Web Form前端2
    SignalR 2.0 系列: SignalR简介
    Amazon前技术副总裁解剖完美技术面试
    MongoDB数据文件内部结构
    SQL Server三种表连接原理
    了解mongoDB存储结构
  • 原文地址:https://www.cnblogs.com/banxianer/p/13607035.html
Copyright © 2011-2022 走看看