小结
Spring Boot报错:没有配置数据源(url属性未设置),进行解决。
问题
Spring Boot报错:
ERROR 2024-08-28 17:24:43.734 [main] -
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable 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 (the profiles default are currently active).
解决
办法一
具体原因,项目调用FeignClient数据源,因此不需要配置数据源,在主应用里关闭数据源的设置。将注@SpringBootApplication
修改如下:
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
办法二
修改build.gradle
配置文件,将以下设置从implementation
改为compileOnly
:
// implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.springframework.boot:spring-boot-starter-data-jpa'
以上,问题解决。