我正在使用Spring Initializr(https://start.spring.io/)生成一个Spring Boot项目. 我将Java版本设置为1.8,因此将Spring Boot版本设置为2.7.16.还添加了Lombok和PostgreSQL依赖项.

但是,当我运行我的项目时,它显示以下日志(log):


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::               (v2.7.16)

2023-10-11 15:07:43.625  INFO 12939 --- [           main] c.j.integrador.IntegradorApplication     : Starting IntegradorApplication using Java 17.0.2 on pc with PID 12939 (/home/<path>/integrador/target/classes started by user in /home/<path>/integrador)
2023-10-11 15:07:43.631  INFO 12939 --- [           main] c.j.integrador.IntegradorApplication     : No active profile set, falling back to 1 default profile: "default"
2023-10-11 15:07:44.783  INFO 12939 --- [           main] c.j.integrador.IntegradorApplication     : Started IntegradorApplication in 1.908 seconds (JVM running for 3.661)

为什么它被设置为Java 17.0.2?

我已经try 对POM.xml进行更改,将以下行添加到POM.xml中,尽管这并没有解决我的问题:

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

例如,下面是我的完整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.16</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.jotec</groupId>
    <artifactId>integrador</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>integrador</name>
    <description>Integrador de Marketplaces</description>
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

推荐答案

为了解决这个问题,我必须设置正确的JRE,以便与我的Java应用程序一起在Eclipse上运行.

最初,我的机器上已经安装了Java 1.8的正确版本.当我运行以下命令时,我设法找到了当前的JRE主路径: $ java -XshowSettings:properties -version

...
java.home = /usr/lib/jvm/java-8-openjdk-amd64/jre
...
OpenJDK Runtime Environment (build 1.8.0_362-8u372-ga~us1-0ubuntu1~18.04-b09)
...

然后,我进入Access Window>Preferences>Java>Installed JREs菜单,添加了一个在JRE主目录中设置指定路径的标准VM(也删除了之前我不会使用的那个).

谢谢您:)

Java相关问答推荐

PostgreSQL货币兑换率查询

表格栏上的事件过滤器在PFA中不起作用

为什么接口中的主函数而不是类中的主函数在Java 17中编译和运行没有问题?

在Java中将Charsequence数组更改为String数组或List String<>

Java Stream,需要更新列表对象列表

屏蔽字母数字代码的Java正则表达式

Java inline Double条件和值解装箱崩溃

在Java Swing Paint应用程序中捕获快速鼠标移动时遇到困难

无法使用ApacheSpark依赖项构建JavaFX应用程序

Mac上的全屏截图在使用JavaFX时不能正常工作吗?

匹配一组字符或另一组字符

如何在antlr4中跳过所有反斜杠-换行符而保留换行符?

使用Jackson库反序列化json

二进制数据的未知编码/序列化

如何创建模块信息类文件并将其添加到JAR中?

具有多个模式的DateTimeForMatter的LocalDate.parse失败

在整数列表中查找和可被第三个整数整除的对时出现无法解释的RunTimeError

模拟JUnit未检测到返回字符串的方法的任何声纳覆盖

如何使用我的RLE程序解决此问题

Xml Reader 将 BMP 外部的字符解析为代理项对,这会导致无效的 xml