Spring boot 数据源未配置异常的解决
Spring boot 数据源未配置异常
问题
在使Springboot自动生成的项目框架时如果选择了数据源,比如选择了mysql,生成项目之后,启动会报一下异常:
Description:
Cannot determine embedded database driver class for database type NONE
Action:
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).
问题分析
导致此问题的原因为,springboot生成的项目启动时会自动注入数据源。而此时在配置文件中并没有配置数据源信息,因此会抛出异常。
解决方案
(1)如果暂时不需要数据源,可将pom文件中的mysql和mybatis(或其他数据源框架)注释掉,即可正常启动。
(2)在@SpringBootApplication中排除其注入
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
(3)提供数据源的配置或其他数据源配置,此处提供默认配置示例,在application.properties文件中添加以下配置项:
# 主数据源,默认的 #spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/test spring.datasource.username=root spring.datasource.password=root
springboot启动提示缺少数据源
If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently
正解:
因为spring boot只要你在pom中引入了mybatis-spring-boot-starter 他就会默认需要加载数据库相关的配置
可以加上
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Java常用正则表达式验证类完整实例【邮箱、URL、IP、电话、身份证等】
这篇文章主要介绍了Java常用正则表达式验证类,结合完整实例形式分析了Java针对邮箱、网址URL、IP地址、电话、身份证等正则验证相关操作技巧,需要的朋友可以参考下2018-12-12
SpringBoot中的@ResponseStatus注解处理异常状态码
这篇文章主要介绍了SpringBoot中的@ResponseStatus注解处理异常状态码,在 SpringBoot 应用程序中,异常处理是一个非常重要的话题。当应用程序出现异常时,我们需要对异常进行处理,以保证应用程序的稳定性和可靠性,需要的朋友可以参考下2023-08-08
springboot yml中profiles的巧妙用法(小白必看多环境配置)
这篇文章主要介绍了springboot yml中profiles的巧妙用法,非常适合多环境配置场景,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2021-04-04
Java语言实现简单FTP软件 FTP上传下载管理模块实现(11)
这篇文章主要为大家详细介绍了Java语言实现简单FTP软件,FTP本地文件管理模块的实现方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-04-04


最新评论