springboot新建项目后在IDEA运行,提示“Failed to configure a DataSource: ‘url‘ attribute is not specified...”
问题描述
运行结果如下所示。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.4.4)
2025-03-28T09:27:18.458+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] c.b.s.SpringBootTestApplication : Starting SpringBootTestApplication using Java 17.0.13 with PID 9336 (E:\Depository_IDEA\SpringBootTest\target\classes started by LJH in E:\Depository_IDEA\SpringBootTest)
2025-03-28T09:27:18.462+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] c.b.s.SpringBootTestApplication : No active profile set, falling back to 1 default profile: "default"
2025-03-28T09:27:18.515+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2025-03-28T09:27:18.515+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2025-03-28T09:27:19.421+08:00 WARN 9336 --- [SpringBootTest] [ restartedMain] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.bjsasc.springboottest]' package. Please check your configuration.
2025-03-28T09:27:19.870+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)
2025-03-28T09:27:19.890+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2025-03-28T09:27:19.891+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.39]
2025-03-28T09:27:20.038+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2025-03-28T09:27:20.038+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1522 ms
2025-03-28T09:27:20.408+08:00 WARN 9336 --- [SpringBootTest] [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
2025-03-28T09:27:20.412+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2025-03-28T09:27:20.433+08:00 INFO 9336 --- [SpringBootTest] [ restartedMain] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-03-28T09:27:20.460+08:00 ERROR 9336 --- [SpringBootTest] [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
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).
进程已结束,退出代码为 0
问题分析
一般是因为SpringBoot自动配置时,检测到我们添加了MySQL、Oracle、Mybatis等和数据库相关的依赖包,结果我们的配置文件中却没有添加数据库相关的配置。
解决方案
待补入此博客全部内容,自己先简单地将数据库和mybatis的maven坐标注释即可运行。