Python 官方文档:入门教程 => 点击学习
Spring Boot 数据源未配置异常 问题 在使SpringBoot自动生成的项目框架时如果选择了数据源,比如选择了Mysql,生成项目之后,启动会报一下异常: Descrip
在使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
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})
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: Spring boot 数据源未配置异常的解决
本文链接: https://www.lsjlt.com/news/131633.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0