怎么解决启动springboot应用因未配置数据库报错问题

发布时间:2021-11-19 13:02:34 作者:iii
来源:亿速云 阅读:332

这篇文章主要讲解了“怎么解决启动springboot应用因未配置数据库报错问题”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么解决启动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

怎么解决启动springboot应用因未配置数据库报错问题

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>

感谢各位的阅读,以上就是“怎么解决启动springboot应用因未配置数据库报错问题”的内容了,经过本文的学习后,相信大家对怎么解决启动springboot应用因未配置数据库报错问题这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. 解决Android AVD启动报错问题
  2. 完美解决linux上启动redis后配置文件未生效的问题

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot

上一篇:python脚本框架webpy怎么安装

下一篇:SpringBoot中Mybatis+Druid数据访问过程是怎样的

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》