java - 我的 application.properties 文件中的属性显示为灰色,我无法配置数据源 : 'url' attribute is not specified

标签 java spring spring-boot spring-data-jpa mysql-connector

配置数据源失败:未指定“url”属性,无法配置嵌入数据源。

大家好,当我在 intelij 中运行应用程序尝试连接到 mysql 时,出现以下错误

2019-09-27 13:26:52.644  WARN 1084 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; 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.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2019-09-27 13:26:52.648  INFO 1084 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-09-27 13:26:52.671  INFO 1084 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-09-27 13:26:52.674 ERROR 1084 --- [  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

我已将以下内容添加到资源文件夹中的 application.properties 文件中

server.port = 8080
spring.servlet.multipart.enabled = false;

spring.jpa.hibernate.ddl-auto = update

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/invoice
spring.datasource.username = root
spring.datasource.password = password

当我查看 application.properties 文件时,我注意到我的属性未使用。 screenshot

这是我的 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>com.jade</groupId>
  <artifactId>invoicesystem</artifactId>
  <version>1.0-SNAPSHOT</version>

  <!-- 1 To convert to springboot application the 1st thing to add is the parent below-->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.5.RELEASE</version>
  </parent>

  <name>invoicesystem</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>




  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>

    <!--2 To convert to springboot application the 2nd thing to do, add dependency: spring-boot-starter-web-->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <version>2.1.5.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <version>2.1.4.RELEASE</version>
      <optional>true</optional>
    </dependency>

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

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

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>

  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>8</source>
          <target>8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

最佳答案

经过深思熟虑,我决定查看一下我的资源文件夹和 application.properties 文件,结果发现资源目录没有标记为资源根目录,右键单击资源文件夹目录,将鼠标悬停在将目录标记为上,然后选择资源根目录 screenshot

抱歉浪费了大家的时间,感谢您为我提供的所有帮助,因为我确实使用了提到的一些配置

关于java - 我的 application.properties 文件中的属性显示为灰色,我无法配置数据源 : 'url' attribute is not specified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58134762/

相关文章:

java - 无法使用 Spring 执行器 - 创建 bean CacheMetricsRegistrarConfiguration 时出错

java - Servlet 初始化内部的 Init 过滤器

java - aspose removeChild 后,run 原来的字体变了

java - 如何将同一个bean实例注入(inject)到多个bean中

mysql - 如何在 Spring Boot 中使用 Thymeleaf 保存角色?

java - Spring Boot - 如何为指定根中的多个路由提供一个静态 html 文件

java - 比较两个 java.util.Date 以查看它们是否在同一天

java - 如何使用 jackson 创建json数组

Spring Boot : RequestRejectedException: The request was rejected because the URL contained a potentially malicious String ";"

java - 如何在 GET 请求中排除其他类对象? - Java Spring启动