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.HikariDataSourcespring.datasource.driverClassName=com.mysql.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/testspring.datasource.username=rootspring.datasource.password=rootspringboot启动提示缺少数据源
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})
以上为个人经验,希望能给大家一个参考,也希望大家多多支持好吧啦网。
相关文章:
1. Python使用oslo.vmware管理ESXI虚拟机的示例参考2. Jsp servlet验证码工具类分享3. .NET6打包部署到Windows Service的全过程4. python GUI库图形界面开发之PyQt5滑块条控件QSlider详细使用方法与实例5. IntelliJ IDEA 好用插件之analyze inspect code详解6. JetBrains IntelliJ IDEA 配置优化技巧7. idea2020.1无法自动加载maven依赖的jar包问题及解决方法8. PHP程序员简单的开展服务治理架构操作详解(一)9. vue项目中使用bpmn为节点添加颜色的方法10. 解决idea update project 更新选项消失的问题
