iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >启动springboot应用因未配置数据库报错的解决方案
  • 370
分享到

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

2024-04-02 19:04:59 370人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

目录启动SpringBoot应用因未配置数据库报错描述解决方案springboot 1.5.8.RELEASE 版本启动报错起因错误排查解决方法启动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>

再次启动就可以了。

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

--结束END--

本文标题: 启动springboot应用因未配置数据库报错的解决方案

本文链接: https://www.lsjlt.com/news/157787.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作