我正在使用Spring Initializr(https://start.spring.io/)生成Sping Boot 项目。我将Java版本设置为1.8,因此Sping Boot 版本为2.7.16。还添加了Lombok和PostgreSQL依赖项。
但是,当我运行项目时,它会显示以下日志:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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?
我已经尝试过将以下行添加到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>
2条答案
按热度按时间kiz8lqtg1#
这些属性只告诉编译器源代码和目标代码(生成的代码)应该符合哪个版本。我认为(但我不确定)它们只传递给
-source
和-target
标志的编译器。这些属性与您用来执行应用程序的Java运行时无关。您使用
Java 17.0.2
启动了spring Boot 应用程序。但这与编译器选项无关。6gpjuf902#
当您将
maven.compiler.source
配置为Java 8时,您要求在Java 8下编译它。在Eclipse中:
maven.compiler.source=8
项目将告诉m2 e使用Java-SE-1.8作为 * 执行环境 *如果您没有这样的“完美匹配”JRE,则需要在首选项中从 *Installed JRE * 中添加一个,然后在 Execution Environments 中选择它