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

本文分析了SpringBoot项目启动时未能正确配置DataSource的问题,并提供了两种解决方案:调整启动类的位置以确保能扫描到必要的组件,或者在启动类中指定多个启动类。

Spring Boot启动过程中遇到了下列这个问题

Description:

Failed to auto-configure a DataSource: 'spring.datasource.url' is not specified and no embedded datasource could be auto-configured.

Reason: Failed to determine suitable jdbc url


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).

主要分析

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

这句话是说数据库不在类路径中,那么是什么导致不在类路径中,初始看到这句话也很懵,各种maven update,删除多余代码等等都不行,然后启动了另一个同git下的项目却发现可以运行,对比两个项目,剔除了业务逻辑后,共同之处无非就是引入共同的jar,然后突然想起Springboot中@SpringBootApplication只会扫描同包及其子包,而报错项目的启动类跟共同jar的包路径不同,导致无法扫描.

解决办法:一:将项目的启动类向外移,使启动类的路径既包含本项目,也包含共同jar

二:在共同jar中添加启动类,然后在项目启动类中SpringApplication.run方法中添加多个启动类,SpringApplication.run(new Class[] { MusicApp.class,CommonApp.class }, args);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值