Spring boot 數(shù)據(jù)源未配置異常的解決
在使Springboot自動(dòng)生成的項(xiàng)目框架時(shí)如果選擇了數(shù)據(jù)源,比如選擇了mysql,生成項(xiàng)目之后,啟動(dòng)會(huì)報(bào)一下異常:
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).
問題分析導(dǎo)致此問題的原因?yàn)?,springboot生成的項(xiàng)目啟動(dòng)時(shí)會(huì)自動(dòng)注入數(shù)據(jù)源。而此時(shí)在配置文件中并沒有配置數(shù)據(jù)源信息,因此會(huì)拋出異常。
解決方案(1)如果暫時(shí)不需要數(shù)據(jù)源,可將pom文件中的mysql和mybatis(或其他數(shù)據(jù)源框架)注釋掉,即可正常啟動(dòng)。
(2)在@SpringBootApplication中排除其注入
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
(3)提供數(shù)據(jù)源的配置或其他數(shù)據(jù)源配置,此處提供默認(rèn)配置示例,在application.properties文件中添加以下配置項(xiàng):
# 主數(shù)據(jù)源,默認(rèn)的#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啟動(dòng)提示缺少數(shù)據(jù)源
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
正解:因?yàn)閟pring boot只要你在pom中引入了mybatis-spring-boot-starter 他就會(huì)默認(rèn)需要加載數(shù)據(jù)庫相關(guān)的配置
可以加上
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Python調(diào)用接口合并Excel表代碼實(shí)例2. 一文透徹詳解.NET框架類型系統(tǒng)設(shè)計(jì)要點(diǎn)3. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁4. 通過CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫特效5. .net如何優(yōu)雅的使用EFCore實(shí)例詳解6. ASP.NET MVC實(shí)現(xiàn)橫向展示購物車7. 通過Ajax方式綁定select選項(xiàng)數(shù)據(jù)的實(shí)例8. ajax動(dòng)態(tài)加載json數(shù)據(jù)并詳細(xì)解析9. Python快速將ppt制作成配音視頻課件的操作方法10. ASP.Net Core對(duì)USB攝像頭進(jìn)行截圖
