Spring Native 0.9.1-SNAPSHOT 无法在 IDEA 中启动

问题描述

刚刚在 https://start.spring.io/ Spring Boot 2.4.4 项目上生成,并添加了 Spring Boot Native 0.9.1-SNAPSHOT

并且它无法在 IDEA 中启动(因此即使作为本机图像也无法启动)

ApplicationContext 无法启动,因为找不到由 Spring AOT 插件生成的“org.springframework.aot.StaticSpringFactories”。

完整输出

/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=52158:/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath ....
2021-03-20 22:07:21.264 ERROR 10192 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION Failed TO START
***************************

Description:

The ApplicationContext Could not start as 'org.springframework.aot.StaticSpringFactories' that is generated by the Spring AOT plugin Could not be found.

Action:

Review your local configuration and make sure that the Spring AOT plugin is configured properly.
If you're trying to run your application with 'mvn spring-boot:run',please use 'mvn package spring-boot:run' instead.
See https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#spring-aot for more details.


Process finished with exit code 1

我注意到 Initializr 添加了一些额外的 maven 插件,用于我通常使用 Web 和 JPA over hibernate 的项目:

    <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>
                    <image>
                        <builder>paketobuildpacks/builder:tiny</builder>
                        <env>
                            <BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
                        </env>
                    </image>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.experimental</groupId>
                <artifactId>spring-aot-maven-plugin</artifactId>
                <version>${spring-native.version}</version>
                <executions>
                    <execution>
                        <id>test-generate</id>
                        <goals>
                            <goal>test-generate</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>generate</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.hibernate.orm.tooling</groupId>
                <artifactId>hibernate-enhance-maven-plugin</artifactId>
                <version>${hibernate.version}</version>
                <executions>
                    <execution>
                        <id>enhance</id>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                        <configuration>
                            <failOnError>true</failOnError>
                            <enableLazyInitialization>true</enableLazyInitialization>
                            <enableDirtyTracking>true</enableDirtyTracking>
                            <enableAssociationManagement>true</enableAssociationManagement>
                            <enableExtendedEnhancement>false</enableExtendedEnhancement>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

解决方法

请仔细阅读https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#spring-aot,它有 IDEA 的确切步骤(以及 Eclipse 和 VSCode 的提示)

在 Maven 工具窗口中,转到“插件”并映射:

  • 右键单击 spring-aot:generate,然后单击“构建后”。

  • 添加 JUnit 配置(或者只是尝试第一次运行您的测试),然后右键单击 `spring-aot:test-generate,然后单击“执行运行/调试 ... ”,然后选择您的 JUnit测试配置。

,

这是在我的 IDE 中配置它的快照。

enter image description here