spring-boot - 无法配置数据源:未指定 'url'属性,并且无法配置任何嵌入式数据源。Gradle项目中的错误

标签 spring-boot tomcat gradle build.gradle

我创建了一个新的Spring Boot Gradle项目。我还没有编码。但是在以Spring Boot的身份运行应用程序时出现错误。我是否需要在这里添加任何其他依赖项?或对此有什么解决方案?
build.gradle

plugins {
    id 'org.springframework.boot' version '2.3.3.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
}

group = 'com.informationbook'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-batch'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation 'org.springframework.batch:spring-batch-test'
}

test {
    useJUnitPlatform()
}
在这里,我包括控制台以供引用。
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.3.RELEASE)

2020-08-29 10:07:44.398  INFO 18616 --- [           main] c.i.InformationBookApplication           : Starting InformationBookApplication on LAPTOP-I4F37P4O with PID 18616 (C:\Users\mitad\Documents\STS_Workspace\Information-Book\bin\main started by mitad in C:\Users\mitad\Documents\STS_Workspace\Information-Book)
2020-08-29 10:07:44.400  INFO 18616 --- [           main] c.i.InformationBookApplication           : No active profile set, falling back to default profiles: default
2020-08-29 10:07:44.892  INFO 18616 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-08-29 10:07:44.897  INFO 18616 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-08-29 10:07:44.897  INFO 18616 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.37]
2020-08-29 10:07:44.945  INFO 18616 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-08-29 10:07:44.945  INFO 18616 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 523 ms
2020-08-29 10:07:45.040  INFO 18616 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-08-29 10:07:45.114  WARN 18616 --- [           main] 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]: 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
2020-08-29 10:07:45.114  INFO 18616 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2020-08-29 10:07:45.116  INFO 18616 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2020-08-29 10:07:45.123  INFO 18616 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-08-29 10:07:45.124 ERROR 18616 --- [           main] 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).

最佳答案

请运行Gradle依赖项并检查依赖项树,控制台将打印

Run gradle dependency , console will print your dependency tree,

+--- org.springframework.boot:spring-boot-starter-batch -> 2.3.3.RELEASE
|    +--- org.springframework.boot:spring-boot-starter:2.3.(*)
|    |    +--- jakarta.annotation:jakarta.annotation-api:1.3.5
|    |    +--- org.springframework:spring-core:5.2.8.RELEASE (*)
|    |    \--- org.yaml:snakeyaml:1.26
|    +--- org.springframework.boot:spring-boot-starter-jdbc:2.3.3.RELEASE

Spring批处理启动程序具有Jdbc启动程序的依赖关系,您可以提供嵌入式数据库依赖关系,也可以在应用程序属性中添加数据库属性
要么
如果您不希望数据库依赖,只需排除自动配置
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})

关于spring-boot - 无法配置数据源:未指定 'url'属性,并且无法配置任何嵌入式数据源。Gradle项目中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63643691/

相关文章:

tomcat - cgi 和 tomcat

authentication - 使用 Tomcat 实现自定义身份验证

tomcat - 无法使用引擎的非 defaultHost 在 tomcat7 中部署 Jenkins

android - Gradle在运行Android工具时会忽略testProguardFile

gradle - 如何为Gradle任务的依赖项设置 `onlyIf`?

java - Spring Cloud Gateway 用于复合 API 调用?

java - Spring Boot中使用gradle构建前端

java - 将 ID 从查询转换为字符串

spring-boot - 如何从应用程序启动中删除 Spring Data CustomConversions 警告?

gradle - 如何在Gradle子项目中使用Gradle Artifactory插件