嘿,我收到这个错误,我无法解决它,感谢的帮助
错误7924-[main]o.s.boot.SpringApplication:应用程序运行失败
创建在类路径资源中定义了名称为"dataSourceScriptDatabaseInitializer"的bean时出错
这是我的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.5.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>employeemanager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>employeemanager</name>
<description>Employee Manager App </description>
<properties>
<java.version>11</java.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-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
和我的application.properties:
# mySQL configuration
spring.datasource.url=jbdc:mysql://localhost:3306/employeemanager
spring.datasource.username=root
spring.datasource.password=letmein
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
在Spring Boot 2.5.X上,data.sql脚本现在在Hibernate初始化之前运行。如果您想使用data.sql来填充Hibernate创建的架构,请尝试将以下内容添加到application.propertiesspring.jpa.defer-datasource-initialization=true
中。
# mySQL configuration
spring.datasource.url=jbdc:mysql://localhost:3306/employeemanager
有一个打字错误,应该是jdbc而不是jbdc
我记得,我在集成过程中也遇到过类似的问题
请验证您的pom.xml和application.properties/application.yaml配置,如下所示。
示例-Maven Pom.xml4.0.0
<groupId>com.example</groupId>
<artifactId>spring-boot-security-oauth2</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.4</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</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>
</project>
应用程序属性-Application.yaml
spring:
datasource:
url: jdbc:mysql://localhost:3306/bootdb
username: root
password: admin
jpa:
hibernate.ddl-auto: update
show-sql: true
user.datasource.driver-class-name: com.mysql.jdbc.Driver
有关更多详细信息,您可以查看以下工作示例:
- https://thebasictechinfo.com/interview-preparation/spring-boot-oauth2-securing-rest-api/
- https://thebasictechinfo.com/java-8/spring-boot-spring-security-with-database-authentication-mysql-rest-api-example/
此外,您可以尝试使用以下属性吗
spring.datasource.jdbcUrl=jdbc:mysql://localhost/bootdb?useSSL=false
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
享受:)