我该如何解决这个问题?

时间:2019-10-17 19:32:19

标签: spring-boot java-ee-8

启动错误

  

ApplicationContext。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序。   2019-10-17 15:44:43.968错误10460 --- [main] o.s.boot.SpringApplication:应用程序运行失败

package com.example.angular;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CrudangularApplication {

    public static void main(String[] args) {
        SpringApplication.run(CrudangularApplication.class, args);
    }

}

我的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.1.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.perf</groupId>
    <artifactId>crudangular</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>crudangular</name>
    <description>Demo project for Spring Boot</description>

    <properties>
    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.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>

这是我的结果

  

启动ApplicationContext时出错。要显示条件报告,请在启用“调试”的情况下重新运行您的应用程序。   2019-10-18 11:05:18.627错误11856 --- [main] o.s.boot.SpringApplication:应用程序运行失败   org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration”的bean时出错:通过构造函数参数0表示的不满意依赖关系;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org / springframework / boot / autoconfigure / jdbc / DataSourceConfiguration $ Hikari.class]中定义的名称为“ dataSource”的bean时出错:通过工厂方法进行Bean实例化失败;嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法'dataSource'引发了异常;嵌套的异常是java.lang.IllegalStateException:无法加载驱动程序类:com.mysql.jdbc.driver       在org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769)〜[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE]

我改变了,但是我遇到了这个错误

com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链接失败

成功发送到服务器的最后一个数据包是0毫秒前。驱动程序尚未收到来自服务器的任何数据包。     在com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)〜[mysql-connector-java-8.0.17.jar:8.0.17]     在com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)〜[mysql-connector-java-8.0.17.jar:8.0.17]     在com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:827)〜[mysql-connector-java-8.0.17.jar:8.0.17]     在com.mysql.cj.jdbc.ConnectionImpl。(ConnectionImpl.java:447)〜[mysql-connector-java-8.0.17.jar:8.0.17]     在com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:237)〜[mysql-connector-java-8.0.17.jar:8.0.17]     在com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)〜[mysql-connector-java-8.0.17.jar:8.0.17]     在com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)〜[HikariCP-3.2.0.jar:na]     在com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)〜[HikariCP-3.2.0.jar:na]     在com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)〜[HikariCP-3.2.0.jar:na]     在com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)[HikariCP-3.2.0.jar:na]     在com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)[HikariCP-3.2.0.jar:na]     在com.zaxxer.hikari.pool.HikariPool。(HikariPool.java:115)[HikariCP-3.2.0.jar:na]     在com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)上[HikariCP-3.2.0.jar:na]     在org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:158)[spring-jdbc-5.1.10.RELEASE.jar:5.1.10.RELEASE]     在org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:116)[spring-jdbc-5.1.10.RELEASE.jar:5.1.10.RELEASE]     在org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)[spring-jdbc-5.1.10.RELEASE.jar:5.1.10.RELEASE]     在org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:320)[spring-jdbc-5.1.10.RELEASE.jar:5.1.10.RELEASE]     

1 个答案:

答案 0 :(得分:1)

您需要在application.yaml文件中设置一个属性

spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver

这是因为MySQL将驱动程序的软件包从com.mysql.jdbc.Driver更改为com.mysql.cj.jdbc.Driver