0
点赞
收藏
分享

微信扫一扫

两种方案解决报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasour


两种方案解决报错:Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasour

文章目录

  • ​​两种方案解决报错:Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasour​​
  • ​​方案一​​
  • ​​方案二​​
  • ​​结语​​

方案一

在@SpringBootApplication后添加exclude = { DataSourceAutoConfiguration.class }来排除自动配置 :

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })

方案二

在application.yml文件中添加排除自动配置

spring:
autoconfigure:
exclude:

两种方案解决报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasour_tomcat

application.properties

spring.autoconfigure.exclude= org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

| '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.7.2)

2022-09-28 17:03:06 [INFO] org.springframework.boot.StartupInfoLogger:55 : Starting JoySpaceApplicationKt using Java 1.8.0_342 on DESKTOP-PFPD85S with PID 12140 (E:\Project-Code\OutsideApi\build\classes\kotlin\main started by DELL in E:\Project-Code\OutsideApi)
2022-09-28 17:03:06 [INFO] org.springframework.boot.SpringApplication:634 : No active profile set, falling back to 1 default profile: "default"
2022-09-28 17:03:06 [INFO] org.springframework.data.repository.config.RepositoryConfigurationDelegate:132 : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-09-28 17:03:06 [INFO] org.springframework.data.repository.config.RepositoryConfigurationDelegate:201 : Finished Spring Data repository scanning in 8 ms. Found 0 JPA repository interfaces.
2022-09-28 17:03:07 [INFO] org.springframework.boot.web.embedded.tomcat.TomcatWebServer:108 : Tomcat initialized with port(s): 6060 (http)
2022-09-28 17:03:07 [INFO] org.apache.juli.logging.DirectJDKLog:173 : Initializing ProtocolHandler ["http-nio-6060"]
2022-09-28 17:03:07 [INFO] org.apache.juli.logging.DirectJDKLog:173 : Starting service [Tomcat]
2022-09-28 17:03:07 [INFO] org.apache.juli.logging.DirectJDKLog:173 : Starting Servlet engine: [Apache Tomcat/9.0.65]
2022-09-28 17:03:07 [INFO] org.apache.juli.logging.DirectJDKLog:173 : Initializing Spring embedded WebApplicationContext
2022-09-28 17:03:07 [INFO] org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext:292 : Root WebApplicationContext: initialization completed in 862 ms
2022-09-28 17:03:07 [WARN] org.springframework.context.support.AbstractApplicationContext:591 : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2022-09-28 17:03:07 [INFO] org.apache.juli.logging.DirectJDKLog:173 : Stopping service [Tomcat]
2022-09-28 17:03:07 [INFO] org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener:136 :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-09-28 17:03:07 [ERROR] org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter:40 :

***************************
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),

两种方案解决报错:Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasour_开发语言_02

兜底方案:

@SpringBootApplication(exclude = {
DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class,
HibernateJpaAutoConfiguration.class})

但是很多时候,加了这个注解,还是不能解决自动寻找配置文件中url进行初始化数据库连接的异常。
原因在于,在pom文件中,使用跟数据库相关的依赖,如spring-data,druid等,需要把数据库相关的依赖去掉,然后再加上注解,就能实现无数据库启动springboot了。

亲测方案2有效~



举报

相关推荐

0 条评论