If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.

学习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   还有有同样的问题, 最后干脆重新新建项目,然后按照教程重新运行了下,没有发现上述的其他问题, 搞不懂什么鬼,先记录在这里!

 

  • 35
    点赞
  • 64
    收藏
    觉得还不错? 一键收藏
  • 68
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 68
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值