温馨提示×

温馨提示×

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

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

Spring boot 启动提示数据源错误怎么办

发布时间:2021-12-24 16:49:30 来源:亿速云 阅读:154 作者:小新 栏目:大数据

这篇文章主要介绍了Spring boot 启动提示数据源错误怎么办,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

在启动 Spring Boot 的项目的时候提示数据源未配置的错误。

09:52:08.333 [main] DEBUG o.s.b.d.LoggingFailureAnalysisReporter - Application failed to start due to an exceptionorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver classat org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:233)	at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:174)

Spring 会提示你完整的导致启动错误的信息是:

***************************
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

错误分析

从上面的启动信息来看,已经说得非常清楚了,就是因为你配置了 Spring 的数据组件,但是你没有配置相应的数据源。

因为这个会导致你的启动失败。

解决办法

有下面的集中解决办法:

加入 H2 包

最简单的解决办法就是在依赖中添加 H2 的数据库,如果你使用 Spring Batch 的话,这个组件也是需要的,因为 Spring 会使用 H2 为数据源。

添加数据源配置

如果你已经添加了数据库驱动,例如你添加了 mysql 的数据库驱动。

那么你需要制定 Mysql 的数据库连接参数。

spring.datasource.url=jdbc:mysql://localhost:3306/myDbspring.datasource.username=user1spring.datasource.password=passspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

在启动时候不载入数据源配置。

你可用在启动的时候不载入数据源配置。

可用在启动类上面,添加下面的注解。

@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})

Spring boot 启动提示数据源错误怎么办

你也可以在启动配置文件上面,添加下面的内容,这样能够保证你在启动的时候不载入数据源配置类。

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAuto

感谢你能够认真阅读完这篇文章,希望小编分享的“Spring boot 启动提示数据源错误怎么办”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

向AI问一下细节

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

AI