拜托,我真的需要帮助。我看过其他类似的问题,但没有一个能解决我的问题。我正在运行一个试图连接到本地数据库的 Spring 应用程序,但我不断收到以下错误
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).
这是我的 application.properties(是的,它在资源文件夹中):
>spring.jpa.hibernate.ddl-auto=create
>spring.datasource.url=jdbc:mysql://localhost:3306/CierraDB
>spring.datasource.username=
>spring.datasource.password=
这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>org.springframework</groupId>
<artifactId>read-db</artifactId>
<version>1.0-SNAPSHOT</version>
<name>mysql-jdbc-driver</name>
<description>example</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
最佳答案
您是否指定了驱动程序类并将带有 mysql 驱动程序类的 jar 包含在您的类路径中?
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
关于java - 配置数据源失败 : Intellij Error when connecting Database to Spring Application,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53328312/