此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.3.1! |
此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Boot 3.3.1! |
当人们使用 Spring Boot 应用程序的提前处理时,经常会出现许多问题。 本节将解决这些问题。
条件
如果要根据提前优化的应用程序中的条件创建的 Bean,则必须在构建应用程序时设置环境。 在构建时提前处理时创建的 Bean 始终在运行应用程序时创建,并且无法关闭。 为此,您可以设置构建应用程序时应使用的配置文件。
对于 Maven,这通过设置执行配置来工作:profiles
spring-boot-maven-plugin:process-aot
<profile>
<id>native</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>process-aot</id>
<configuration>
<profiles>profile-a,profile-b</profiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
对于 Gradle,您需要配置以下任务:ProcessAot
tasks.withType(org.springframework.boot.gradle.tasks.aot.ProcessAot).configureEach {
args('--spring.profiles.active=profile-a,profile-b')
}
在运行提前优化的应用程序时,支持仅更改不影响条件的配置属性的配置文件,不受限制。