为了账号安全,请及时绑定邮箱和手机立即绑定

我的 application.properties 文件中的属性呈灰色

我的 application.properties 文件中的属性呈灰色

吃鸡游戏 2023-09-06 14:58:05
无法配置数据源:未指定“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 class2019-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
查看完整描述

3 回答

?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

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

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


查看完整回答
反对 回复 2023-09-06
?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

看起来像依赖性问题尝试指定驱动程序的版本:


<dependency>

    <groupId>mysql</groupId>

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

    <version>8.0.17</version>

</dependency>


查看完整回答
反对 回复 2023-09-06
?
弑天下

TA贡献1818条经验 获得超8个赞

您好,在您的财产文件上设置:


spring.datasource.url=jdbc:mysql://localhost:3306/invoice

spring.datasource.username=root

spring.datasource.password=password

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

在你的 pom.xml 上


<parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>2.1.7.RELEASE</version>

    <relativePath/>

</parent>


<properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <maven.compiler.source>1.8</maven.compiler.source>

    <maven.compiler.target>1.8</maven.compiler.target>

</properties>


<dependencies>


    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter</artifactId>

    </dependency>


    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-devtools</artifactId>

        <optional>true</optional>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-data-jpa</artifactId>

    </dependency>


    <dependency>

        <groupId>mysql</groupId>

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

        <scope>runtime</scope>

    </dependency>

    <!-- ... -->

</dependencies>


<build>

    <plugins>

        <plugin>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-maven-plugin</artifactId>

            <configuration>

                <mainClass>yourpackage.YourInitialApp</mainClass>

            </configuration>

            <executions>

                <execution>

                    <goals>

                        <goal>repackage</goal>

                    </goals>

                </execution>

            </executions>

        </plugin>

    </plugins>

</build>

我的github


查看完整回答
反对 回复 2023-09-06
  • 3 回答
  • 0 关注
  • 368 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信