首先看一下报错记录
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 (no profiles are currently active).
提示 数据库配置问题:
看一下数据库,发现没有问题
spring.datasource.username=root
spring.datasource.password=root123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
mybatis.mapper-locations=classpath:mapper/*.xml
网上查了一大堆,有添加注解的,有添加(可以解决)
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
``
仔细看了一眼
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/75dc554debf64f48ac0093d1dbc35f6d.png)
自己的配置文件,应该是配置文件没生效
文件命名错误:确保文件名正确,大小写敏感。在 Spring Boot 中,通常使用 application-{profile}.properties 或 application-{profile}.yml 格式。
文件位置错误:application-dev.properties 应该放在 src/main/resources 目录下。如果放在其他地方,IDE 可能无法正确识别。
IDE 配置问题:检查 IDE 是否配置为识别 Spring Boot 项目。在某些情况下,IDE 需要特定的插件或设置才能识别 Spring Boot 项目结构。
Spring Boot 依赖未添加:确保你的项目中已经包含了 Spring Boot 的依赖。如果没有,IDE 可能不会识别为 Spring Boot 项目。
Spring Boot 配置文件不支持:虽然 Spring Boot 支持 .properties 和 .yml 文件,但某些 IDE 可能对 .yml 文件的支持更好。尝试将 .properties 文件改为 .yml 格式,例如 application-dev.yml。
IDE 缓存问题:有时候,IDE 的缓存可能会导致问题。尝试清除缓存并重启 IDE。
Spring Boot Profile 未激活:在 Spring Boot 中,需要在启动应用程序时激活特定的 profile。例如,使用命令行启动时,可以添加 -Dspring.profiles.active=dev 来激活开发环境配置。
IDE 插件问题:如果你使用的是特定的 IDE 插件来支持 Spring Boot,确保插件是最新的,并且正确安装。
最终解决。