我一直在用Spring开发微服务。我写了几个,都很成功,但是最后一个失败了,我不知道为什么。
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
我的application.properties:
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/Sat
spring.datasource.username=user_auto
spring.datasource.password=
(Don“不用担心,密码包含在www.example.com中application.properties)
已尝试添加和删除:
数据源自动配置
我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sat.serviciodescargamasiva.automatizador</groupId>
<artifactId>automatizador</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>automatizador</name>
<description>Servicio de automatizador del SAT</description>
<properties>
<java.version>11</java.version>
<spring-cloud-gcp.version>3.2.1</spring-cloud-gcp.version>
<spring-cloud.version>2021.0.2</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-storage</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-dependencies</artifactId>
<version>${spring-cloud-gcp.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
我主要:
@SpringBootApplication公共类自动应用程序{
public static void main(String[] args) {
SpringApplication.run(AutoApplication.class, args);
}
}
我正在用IntelliJ写代码。帮帮忙,我不知道该怎么办!我想我已经没有可能的解决方案了。
提前感谢您抽出时间!
3条答案
按热度按时间2fjabf4q1#
尝试删除此依赖项:
我不确定它是否可以与mysql驱动程序相结合:
您也可以尝试更改此选项:
或者,根据Baeldung将其更改为:
cbjzeqam2#
我也遇到了同样的问题。我也尝试了答案中给出的不同解决方案,但没有一个对我有效。我最终发现问题出在pom.xml上(如果您的依赖管理器是maven的话)。我在那里有下面的代码块&在删除它之后,问题就解决了。
问题是spring自动配置无法检测到正确的资源文件夹。删除此文件夹不会对您的程序造成任何损害。
2vuwiymt3#
检查你的pom.xml文件,确保它的 Package 是war。它对我很有效:)