Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法运行Spring启动应用程序,原因是加载驱动程序类com.mysql.jdbc.driver失败_Java_Mysql_Sql_Spring_Spring Boot - Fatal编程技术网

Java 无法运行Spring启动应用程序,原因是加载驱动程序类com.mysql.jdbc.driver失败

Java 无法运行Spring启动应用程序,原因是加载驱动程序类com.mysql.jdbc.driver失败,java,mysql,sql,spring,spring-boot,Java,Mysql,Sql,Spring,Spring Boot,将Flyway添加到项目时出现此错误。 现在我无法运行该应用程序,因为出现了此错误。我尝试更改mysql版本,但这没有帮助。另外,我删除了V1_uuinit_DB.sql和V2_uadd_admin.sql(为Flyway创建的文件),但应用程序仍然没有运行。我在stackoverflow和其他网站上读了很多答案,但仍然没有解决这个问题的方法 ERROR 12860 --- [ restartedMain] com.zaxxer.hikari.HikariConfig :

将Flyway添加到项目时出现此错误。 现在我无法运行该应用程序,因为出现了此错误。我尝试更改mysql版本,但这没有帮助。另外,我删除了V1_uuinit_DB.sql和V2_uadd_admin.sql(为Flyway创建的文件),但应用程序仍然没有运行。我在stackoverflow和其他网站上读了很多答案,但仍然没有解决这个问题的方法

ERROR 12860 --- [  restartedMain] com.zaxxer.hikari.HikariConfig           : Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader jdk.internal.loader.ClassLoaders$AppClassLoader@5fa7e7ff
WARN 12860 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$3c93ce13]: Constructor threw exception; nested exception is 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.context.properties.bind.BindException: Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource
INFO 12860 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
INFO 12860 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
ERROR 12860 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under '' to com.zaxxer.hikari.HikariDataSource:

    Property: driverclassname
    Value: com.mysql.jdbc.Driver
    Origin: "driverClassName" from property source "source"
    Reason: Unable to set value for property driver-class-name

Action:

Update your application's configuration
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>coding</groupId>
    <artifactId>application</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>

        <groupId>org.springframework</groupId>
        <artifactId>gs-mysql-data</artifactId>
        <version>0.1.0</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- freemarker -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- database -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>

        </dependency>

        <dependency>
             <groupId>org.flywaydb</groupId>
             <artifactId>flyway-core</artifactId>
                <version>5.1.4</version>
         </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.3.170</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.4.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.2.3.Final</version>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.14</version>
        </dependency>

        <!-- security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!-- spring boot mail -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>5.1.4</version>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

我将spring.datasource.driver class name=com.mysql.cj.jdbc.driver放入application.properties,它删除了我上面描述的错误,但现在我有另一个错误:

WARN 7588 --- [  restartedMain] org.flywaydb.core.Flyway                 : Flyway.setCallbacks(FlywayCallback) has been deprecated and will be removed in Flyway 6.0. Use Flyway.setCallbacks(Callback) instead.
INFO 7588 --- [  restartedMain] o.f.core.internal.util.VersionPrinter    : Flyway Community Edition 5.1.4 by Boxfuse
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
INFO 7588 --- [  restartedMain] o.f.c.internal.database.DatabaseFactory  : Database: jdbc:mysql://localhost:3306/twitterclone (MySQL 8.0)
WARN 7588 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected failed migration to version 1 (Init DB)
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
INFO 7588 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

从错误消息来看,您可能只是错过了
应用程序中的以下内容。properties

spring.datasource.driver类名=com.mysql.jdbc.driver
引述:

您至少应该通过设置spring.datasource.URL属性来指定URL。否则,SpringBoot将尝试自动配置嵌入式数据库

您通常不需要指定驱动程序类名,因为Spring Boot可以从url推断出大多数数据库的驱动程序类名

对于要创建的池数据源,我们需要能够验证是否有有效的驱动程序类可用,所以我们在执行任何操作之前都要检查它。换句话说,如果您设置了
spring.datasource.driver class name=com.mysql.jdbc.driver
,那么该类必须是可加载的


我将spring.datasource.driver class name=com.mysql.cj.jdbc.driver放入application.properties,现在我在创建名为“flywayInitializer”的bean时遇到另一个错误,该bean在类路径资源[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]中定义:初始化方法调用失败;嵌套的异常是org.flywaydb.core.api.flywayexception您应该将整个日志发布到某个pastebin上,但这是另一个问题
WARN 7588 --- [  restartedMain] org.flywaydb.core.Flyway                 : Flyway.setCallbacks(FlywayCallback) has been deprecated and will be removed in Flyway 6.0. Use Flyway.setCallbacks(Callback) instead.
INFO 7588 --- [  restartedMain] o.f.core.internal.util.VersionPrinter    : Flyway Community Edition 5.1.4 by Boxfuse
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
INFO 7588 --- [  restartedMain] o.f.c.internal.database.DatabaseFactory  : Database: jdbc:mysql://localhost:3306/twitterclone (MySQL 8.0)
WARN 7588 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Validate failed: Detected failed migration to version 1 (Init DB)
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
INFO 7588 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
INFO 7588 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]