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

网友投稿 879 2022-11-21

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

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

目录启动springboot应用因未配置数据库报错描述解决方案springboot 1.5.8.RELEASE 版本启动报错起因错误排查解决方法

启动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 specifihttp://ed and no embedded datasource could be configured.

Reason: Failed to deterhttp://mine 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-.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查wZqhfXVC找后,发现没这个类。

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中加入

org.springframework

spring-core

4.3.9.RELEASE

再次启动就可以了。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:从hbase读取数据,经过 MR 计算,将结果存储于hdfs的实现
下一篇:常见异常的解决
相关文章

 发表评论

暂时没有评论,来抢沙发吧~