【问题标题】:Spring Error LoggingFailureAnalysisReporter after Initialize new project初始化新项目后的 Spring 错误 LoggingFailureAnalysisReporter
【发布时间】:2020-08-06 22:32:09
【问题描述】:

我使用Spring Initializr 创建了一个新项目,并在导入 Intellij 后运行它,IDE 生成的代码没有任何更改,我收到以下错误:

restartedMain] o.s.b.d.LoggingFailureAnalysisReporter

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

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


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).


Process finished with exit code 0

我的 pom.xml 是:

    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jdbc</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-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </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>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

MariaDB 版本:10.3.23

春季版:2.3.2

Java 版本:openjdk 1.8.0_252

【问题讨论】:

    标签: java mysql spring


    【解决方案1】:

    此错误来自以下目录下 application.properties 的错误数据库配置:/src/main/resources 阅读:this github repo 了解您可以并且应该在 application.properties 中使用的所有设置,但对于您的简单项目,请使用以下说明:

    将这行代码添加到 application.properties:

    # ===============================
    # = DATA SOURCE
    # ===============================
    
    # Set here configurations for the database connection
    
    # Connection url for the database "netgloo_blog"
    spring.datasource.url = jdbc:mysql://localhost:3306/netgloo_blog?useSSL=false
    
    # Username and password
    spring.datasource.username = root
    spring.datasource.password = root
    
    # Keep the connection alive if idle for a long time (needed in production)
    spring.datasource.testWhileIdle = true
    spring.datasource.validationQuery = SELECT 1
    
    # ===============================
    # = JPA / HIBERNATE
    # ===============================
    
    # Use spring.jpa.properties.* for Hibernate native properties (the prefix is
    # stripped before adding them to the entity manager).
    
    # Show or not log for each sql query
    spring.jpa.show-sql = true
    
    # Hibernate ddl auto (create, create-drop, update): with "update" the database
    # schema will be automatically updated accordingly to java entities found in
    # the project
    spring.jpa.hibernate.ddl-auto = update
    
    # Naming strategy
    spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
    
    # Allows Hibernate to generate SQL optimized for a particular DBMS
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    

    此基本配置将使您摆脱麻烦,但请记住更改 MySQL 或 MariaDB 数据库的用户名和密码。 您可以使用this topic 了解有关在 spring 和 jhipster 项目中更改数据库用户和密码的更多信息

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多