欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-04-19 22:40:36
...

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

相关标签: springboot