提前处理

当人们使用Spring Boot应用程序的提前处理时,常常会遇到许多问题。 本节将回答这些问题。spring-doc.cadn.net.cn

条件

提前处理优化应用并进行评估@Conditional基于构建时环境的注释。配置文件是通过条件实现的,因此也会受到影响。spring-doc.cadn.net.cn

如果你想要基于某个条件在提前优化的应用中创建豆子,你必须在构建应用时先设置环境。 在构建时提前处理时创建的豆子,总是在运行应用时生成,无法关闭。 为此,你可以设置构建应用时应使用的用户配置文件。spring-doc.cadn.net.cn

对于Maven,这通过设置配置 文件配置Spring-boot-Maven-Plugin:process-aot执行:spring-doc.cadn.net.cn

<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任务:spring-doc.cadn.net.cn

tasks.withType(org.springframework.boot.gradle.tasks.aot.ProcessAot).configureEach {
    args('--spring.profiles.active=profile-a,profile-b')
}

在运行提前优化的应用程序时,支持仅改变不影响条件的配置属性的配置文件,且没有任何限制。spring-doc.cadn.net.cn