解決If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.問題
springboot項(xiàng)目搭建遇到問題,提供兩種解決方法:
“Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.”
表示沒有指定的數(shù)據(jù)庫url,無法配置數(shù)據(jù)庫

image.png
方法一:不使用數(shù)據(jù)源配置
我們可以在Spring Boot項(xiàng)目入口注解處添加 exclude= {DataSourceAutoConfiguration.class},表示取消數(shù)據(jù)源的自動(dòng)配置
如:
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; /** * 表示取消數(shù)據(jù)源的自動(dòng)配置 */ @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) public class SpringbootWeb01Application { public static void main(String[] args) { SpringApplication.run(SpringbootWeb01Application.class, args); } }
方法二:按照報(bào)錯(cuò),我們添加數(shù)據(jù)庫配置
我們需要application.yml文件下添加如下配置
server: port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/springboottest driver-class-name: com.mysql.cj.jdbc.Driver password: 88888888 username: jiade
作者:程序員溪言
鏈接:https://www.jianshu.com/p/54db85befb01
來源:簡書
著作權(quán)歸作者所有。商業(yè)轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),非商業(yè)轉(zhuǎn)載請注明出處。
posted on 2021-12-15 19:59 星期五 閱讀(671) 評論(0) 編輯 收藏 所屬分類: J2EE 、spring-boot