启动springboot因未配置数据库报错 启动springboot应用因未配置数据库报错的解决方案

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

启动springboot因未配置数据库报错 启动springboot应用因未配置数据库报错的解决方案

奇思妙想小小陈   2021-11-19 我要评论
想了解启动springboot应用因未配置数据库报错的解决方案的相关内容吗,奇思妙想小小陈在本文为您仔细讲解启动springboot因未配置数据库报错的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:启动springboot应用,未配置数据库报错,下面大家一起来学习吧。

启动springboot应用因未配置数据库报错

描述

创建一个全新的springboot项目,第一次启动时报错,具体错误信息如下所示:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-06-14 17:58:10.322 ERROR 12292 --- [ main] 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).

Process finished with exit code 1

解决方案

方案一

在application.properties配置文件中添加数据库配置信息

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8
spring.datasource.username=cx
spring.datasource.password=123456

方案二

在启动类头部声明进行声明:

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

springboot 1.5.8.RELEASE 版本启动报错

起因

新建spring boot项目选择1.5.8.RELEASE版本后生成项目,配置好application.properties后启动项目,报错。

Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.EnvironmentCapable
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)

错误排查

1.ctrl+shift+t查找后,发现没这个类。

2.从这个类的全名不能发现,这个类是属于spring-core.jar下的。

3.在maven dependencies中查看spring-core的版本是4.3.12.RELEASE

4.网上查询可知spring-core4.3.12.RELEASE中没有这个类。

解决方法

找到有这个类的spring-core版本。我用的是 4.3.9.RELEASE。然后在dependencies中加入

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>4.3.9.RELEASE</version>
</dependency>

再次启动就可以了。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们