【异常】Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource
2023-09-14 09:04:55 时间
一、报错内容
***************************
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 monitor are currently active).
二、报错原因
查看代码中的配置,看起来没有什么问题,但是就是启动时报错
@SpringBootApplication
public class SpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootApplication.class, args);
}
}
因为是Dubbo微服务架构,集成了common包,里面POM文件中定义了MybatisPlus + MySQL相关的依赖,而SpringBoot扫描到了这些个依赖,但是我们又没有在配置文件中配置与Datasource相关的内容,因此会爆这个错。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3</version>
</dependency>
三、问题解决
直接在SpringBoot启动的时候,移除DataSource的扫描即可,
即将文件修改为@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
即可
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class IdsAepApplication {
public static void main(String[] args) {
SpringApplication.run(IdsAepApplication.class, args);
}
@Bean
MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
return registry -> registry.config().commonTags("application", applicationName);
}
}
https://blog.csdn.net/yetaodiao/article/details/126562162
四、扩展说明
4.1 一般网关不需要配置数据库
相关文章
- dtools: error while loading shared libraries: libicui18n.so.55: cannot open shared object file: No such file or directory ninja: build stopped: subcommand failed.
- ERROR [org.apache.hadoop.util.Shell] - Failed to locate the winutils binary in the hadoop binary path
- java.lang.IllegalStateException: Failed to load ApplicationContext selenium 异常 解决
- Gradle sync failed 异常
- jenkins:配置密钥时报错的解决:Failed to add SSH key. Message invalid privatekey(Jenkins 2.257)
- EasyDSS流媒体服务器Linux emerg getpwnam("xxx") failed解决办法
- Python pip install报错SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED]
- The request failed with HTTP status 401: Unauthorized
- vboxdrv.sh failed modprobe vboxdrv failed. Please use 'dmesg' to find out why
- 处理:Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY error: Failed dependencies:
- failed to create symbolic link ‘/usr/bin/mysql’: File exists
- 问题解决:Failed to start etcd.service: Unit is masked.
- Ubuntu 20.04.3 启动sshd失败,报错:Failed to start OpenBSD Secure Shell server
- Failed dependencies: 检查依赖性错误 解决方法
- Failed to load JavaHL Library.
- 【异常】IDEA中Maven插件提示异常Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin
- 解决办法:nohup: failed to run command ‘java‘: No such file or directory