學習Spring Boot 過程中遇到了下列這個問題
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
//無法配置數據庫,沒有指定url屬性,並且無法配置embedded datasource
Reason: Failed to determine a suitable driver class
//原因:無法明確指定正確的驅動類(driver.class)
Action:
Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
//建議:
//如果如果需要加載嵌入式的數據庫,請將他放入路徑中
//如果有數據庫設置需要從指定配置文件中加載,需要調用該配置文件(目前沒有活動的配置文件)
Process finished with exit code 1
在網上找了很多答案,
其中的一篇:https://www.cnblogs.com/yourGod/p/9178515.html
按照上述的解決辦法:)
程序入口處:
@SpringBootApplication
public class DemoApplication {
修改為:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class DemoApplication {
也許你改成這樣子 ,問題就解決了, 但是我的沒有解決,加了這個產生了一個新的問題:
Description:
Field userRepository in com.wcyq.demo.service.impl.UserServiceImpl required a bean of type 'com.wcyq.demo.domain.UserRepository' that could not be found.
Action:
Consider defining a bean of type 'com.wcyq.demo.domain.UserRepository' in your configuration.
Process finished with exit code 1
出現這個問題,看看是否 程序入口的 xxxApplication.java 是否在最外層的包下.如果不是,把該類放在最外層的包下面
參考自:https://blog.csdn.net/zhouyingge1104/article/details/78267882/
也許你走到這一步,問題就已經得到解決了
但是我發現上面這篇還是沒有能夠幫助到我. 依然還是上述問題提示錯誤信息.
繼續尋找錯誤
是否缺少注解
@Service //該注解必須加上,否者會導致上述錯誤
public class UserServiceImpl implements UserService {
參考自:https://blog.csdn.net/cutterwolf/article/details/77862652
但是我發現我加了注解,還是一樣有這個錯誤,怎么辦?
還是包沒有掃到,繼續添加:
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class,scanBasePackages={ "com.wcyq.demo"})
public class DemoApplication {
程序依舊還是那個錯誤;
后面又找了一下問題,把程序全部rebuild 還有有同樣的問題, 最后干脆重新新建項目,然后按照教程重新運行了下,沒有發現上述的其他問題, 搞不懂什么鬼,先記錄在這里!
---------------------
作者:一往無前-千夜
來源:CSDN
原文:https://blog.csdn.net/wolfking0608/article/details/82886062
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!