【问题标题】:Spring boot - unused properties in aplication.propertiesSpring boot - aplication.properties 中未使用的属性
【发布时间】:2022-12-19 00:59:52
【问题描述】:

你知道为什么 IntelliJ IDEA Community Edition 2022.02.1 在 aplication.properties 中看不到属性吗? enter image description here 编译器是否识别并使用它们,即使它看不到它们? 如果您需要有关此问题的更多信息,请问我,我会尽快回信。

这是我的 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.7.3</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>18</java.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>org.postgresql</groupId>
            <artifactId>postgresql</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>

【问题讨论】:

  • 它是社区版,不支持 Spring、Spring Boot 等。你需要 Ultimate 版。

标签: java spring-boot


【解决方案1】:

Spring & Spring Boot assistance 带有 IntelliJ IDEA Ultimate,它可以检测你所有的 Bean(连同它的用法和注入)、Rest Controller 端点、应用程序属性(连同使用这些属性的类)、Spring 相关的自动完成等。上述功能在 IntelliJ IDEA Community Edition 中不可用,这就是为什么您将这些应用程序属性视为未使用的原因。不过,实际上,它正在被使用,您的应用程序应该可以很好地接收它们(假设您已正确设置)。

然而,这些缺失的功能不应阻止您使用 IntelliJ IDEA Community Edition 开发 Spring Boot(或与此相关的任何 JVM 框架)应用程序。

【讨论】:

    【解决方案2】:

    由于 application.properties 不在源文件夹中,名称 src/main/resource 可能就是这样

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-19
      • 2019-02-04
      • 2021-09-19
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      相关资源
      最近更新 更多