springboot胖罐的graalvm本机映像在运行时抛出NoSuchMethodException xxx。<init>()

时间:2020-06-13 10:26:09

标签: spring-boot graalvm-native-image

我设法为springboot胖罐构建了本地映像,但是运行它时会引发异常:“ java.lang.NoSuchMethodException: com.my.passgenerator.PassGeneratorApplication.<init>()”。 我试图添加一个默认构造和一个空的init()方法,但都失败了。我该如何克服此异常并使此本机映像运行?

以下是完整的日志:


    [root@hostserver pass-generator]# mvn -Pstg clean package -Dmaven.test.skip=true
    [INFO] Scanning for projects...
    [WARNING] 
    [WARNING] Some problems were encountered while building the effective model for com.sensetime.intersense:pass-generator:jar:0.0.1-stg-SNAPSHOT
    [WARNING] 'version' contains an expression but should be a constant. @ com.sensetime.intersense:pass-generator:0.0.1-${target.env}-SNAPSHOT, /tmp/pass-generator/pom.xml, line 47, column 11
    [WARNING] 
    [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
    [WARNING] 
    [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
    [WARNING] 
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building pass-generator 0.0.1-stg-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ pass-generator ---
    [INFO] Deleting /tmp/pass-generator/target
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ pass-generator ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] Copying 1 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ pass-generator ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 10 source files to /tmp/pass-generator/target/classes
    [INFO] 
    [INFO] --- maven-antrun-plugin:1.8:run (default) @ pass-generator ---
    [INFO] Executing tasks

    main:
         [copy] Copying 3 files to /tmp/pass-generator/target/classes/refs
         [copy] Copied 5 empty directories to 1 empty directory under /tmp/pass-generator/target/classes/refs
         [copy] Copying 1 file to /tmp/pass-generator/target/classes
         [copy] Warning: Could not find file /tmp/pass-generator/target/classes/application-stg.yml to copy.
         [copy] Warning: Could not find file /tmp/pass-generator/target/classes/bootstrap-stg.yml to copy.
         [copy] Warning: Could not find file /tmp/pass-generator/target/classes/application-stg.yaml to copy.
         [copy] Warning: Could not find file /tmp/pass-generator/target/classes/config-stg.properties to copy.
    [INFO] Executed tasks
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ pass-generator ---
    [INFO] Not copying test resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ pass-generator ---
    [INFO] Not compiling test sources
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ pass-generator ---
    [INFO] Tests are skipped.
    [INFO] 
    [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ pass-generator ---
    [INFO] Building jar: /tmp/pass-generator/target/pass-generator-0.0.1-stg-SNAPSHOT.jar
    [INFO] 
    [INFO] --- native-image-maven-plugin:20.1.0:native-image (default) @ pass-generator ---
    [INFO] ImageClasspath Entry: org.springframework.boot:spring-boot-starter:jar:2.3.0.RELEASE:compile (file:///root/.m2/repository/org/springframework/boot/spring-boot-starter/2.3.0.RELEASE/spring-boot-starter-2.3.0.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.springframework.boot:spring-boot:jar:2.3.0.RELEASE:compile (file:///root/.m2/repository/org/springframework/boot/spring-boot/2.3.0.RELEASE/spring-boot-2.3.0.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.springframework:spring-context:jar:5.2.6.RELEASE:compile (file:///root/.m2/repository/org/springframework/spring-context/5.2.6.RELEASE/spring-context-5.2.6.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.springframework:spring-aop:jar:5.2.6.RELEASE:compile (file:///root/.m2/repository/org/springframework/spring-aop/5.2.6.RELEASE/spring-aop-5.2.6.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.springframework:spring-beans:jar:5.2.6.RELEASE:compile (file:///root/.m2/repository/org/springframework/spring-beans/5.2.6.RELEASE/spring-beans-5.2.6.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.springframework:spring-expression:jar:5.2.6.RELEASE:compile (file:///root/.m2/repository/org/springframework/spring-expression/5.2.6.RELEASE/spring-expression-5.2.6.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.springframework.boot:spring-boot-autoconfigure:jar:2.3.0.RELEASE:compile (file:///root/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.3.0.RELEASE/spring-boot-autoconfigure-2.3.0.RELEASE.jar)
    [INFO] ImageClasspath Entry: jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile (file:///root/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar)
    [INFO] ImageClasspath Entry: org.springframework:spring-core:jar:5.2.6.RELEASE:compile (file:///root/.m2/repository/org/springframework/spring-core/5.2.6.RELEASE/spring-core-5.2.6.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.springframework:spring-jcl:jar:5.2.6.RELEASE:compile (file:///root/.m2/repository/org/springframework/spring-jcl/5.2.6.RELEASE/spring-jcl-5.2.6.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.yaml:snakeyaml:jar:1.26:compile (file:///root/.m2/repository/org/yaml/snakeyaml/1.26/snakeyaml-1.26.jar)
    [INFO] ImageClasspath Entry: org.projectlombok:lombok:jar:1.18.0:compile (file:///root/.m2/repository/org/projectlombok/lombok/1.18.0/lombok-1.18.0.jar)
    [INFO] ImageClasspath Entry: org.springframework.boot:spring-boot-configuration-processor:jar:2.3.0.RELEASE:compile (file:///root/.m2/repository/org/springframework/boot/spring-boot-configuration-processor/2.3.0.RELEASE/spring-boot-configuration-processor-2.3.0.RELEASE.jar)
    [INFO] ImageClasspath Entry: org.apache.commons:commons-lang3:jar:3.7:compile (file:///root/.m2/repository/org/apache/commons/commons-lang3/3.7/commons-lang3-3.7.jar)
    [INFO] ImageClasspath Entry: org.springframework.boot:spring-boot-starter-logging:jar:2.3.0.RELEASE:compile (file:///root/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.3.0.RELEASE/spring-boot-starter-logging-2.3.0.RELEASE.jar)
    [INFO] ImageClasspath Entry: ch.qos.logback:logback-classic:jar:1.2.3:compile (file:///root/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar)
    [INFO] ImageClasspath Entry: ch.qos.logback:logback-core:jar:1.2.3:compile (file:///root/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar)
    [INFO] ImageClasspath Entry: org.slf4j:slf4j-api:jar:1.7.30:compile (file:///root/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar)
    [INFO] ImageClasspath Entry: org.apache.logging.log4j:log4j-to-slf4j:jar:2.13.2:compile (file:///root/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.13.2/log4j-to-slf4j-2.13.2.jar)
    [INFO] ImageClasspath Entry: org.apache.logging.log4j:log4j-api:jar:2.13.2:compile (file:///root/.m2/repository/org/apache/logging/log4j/log4j-api/2.13.2/log4j-api-2.13.2.jar)
    [INFO] ImageClasspath Entry: org.slf4j:jul-to-slf4j:jar:1.7.30:compile (file:///root/.m2/repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar)
    [INFO] ImageClasspath Entry: org.jasypt:jasypt:jar:1.9.2:compile (file:///root/.m2/repository/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar)
    [INFO] ImageClasspath Entry: com.github.ulisesbocchio:jasypt-spring-boot:jar:2.0.0:compile (file:///root/.m2/repository/com/github/ulisesbocchio/jasypt-spring-boot/2.0.0/jasypt-spring-boot-2.0.0.jar)
    [INFO] ImageClasspath Entry: org.springframework.experimental:spring-graalvm-native:jar:0.7.0:compile (file:///root/.m2/repository/org/springframework/experimental/spring-graalvm-native/0.7.0/spring-graalvm-native-0.7.0.jar)
    [WARNING] jar:file:///root/.m2/repository/org/springframework/experimental/spring-graalvm-native/0.7.0/spring-graalvm-native-0.7.0.jar!/META-INF/native-image/org.springframework.experimental/spring-graal-native/native-image.properties does not match recommended META-INF/native-image/${groupId}/${artifactId}/native-image.properties layout.
    [INFO] ImageClasspath Entry: com.sensetime.intersense:pass-generator:jar:0.0.1-stg-SNAPSHOT (file:///tmp/pass-generator/target/pass-generator-0.0.1-stg-SNAPSHOT.jar)
    [INFO] Executing: /root/graalvm-ce-java8-20.1.0/jre/bin/native-image -cp /root/.m2/repository/org/springframework/boot/spring-boot-starter/2.3.0.RELEASE/spring-boot-starter-2.3.0.RELEASE.jar:/root/.m2/repository/org/springframework/boot/spring-boot/2.3.0.RELEASE/spring-boot-2.3.0.RELEASE.jar:/root/.m2/repository/org/springframework/spring-context/5.2.6.RELEASE/spring-context-5.2.6.RELEASE.jar:/root/.m2/repository/org/springframework/spring-aop/5.2.6.RELEASE/spring-aop-5.2.6.RELEASE.jar:/root/.m2/repository/org/springframework/spring-beans/5.2.6.RELEASE/spring-beans-5.2.6.RELEASE.jar:/root/.m2/repository/org/springframework/spring-expression/5.2.6.RELEASE/spring-expression-5.2.6.RELEASE.jar:/root/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.3.0.RELEASE/spring-boot-autoconfigure-2.3.0.RELEASE.jar:/root/.m2/repository/jakarta/annotation/jakarta.annotation-api/1.3.5/jakarta.annotation-api-1.3.5.jar:/root/.m2/repository/org/springframework/spring-core/5.2.6.RELEASE/spring-core-5.2.6.RELEASE.jar:/root/.m2/repository/org/springframework/spring-jcl/5.2.6.RELEASE/spring-jcl-5.2.6.RELEASE.jar:/root/.m2/repository/org/yaml/snakeyaml/1.26/snakeyaml-1.26.jar:/root/.m2/repository/org/projectlombok/lombok/1.18.0/lombok-1.18.0.jar:/root/.m2/repository/org/springframework/boot/spring-boot-configuration-processor/2.3.0.RELEASE/spring-boot-configuration-processor-2.3.0.RELEASE.jar:/root/.m2/repository/org/apache/commons/commons-lang3/3.7/commons-lang3-3.7.jar:/root/.m2/repository/org/springframework/boot/spring-boot-starter-logging/2.3.0.RELEASE/spring-boot-starter-logging-2.3.0.RELEASE.jar:/root/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar:/root/.m2/repository/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:/root/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/root/.m2/repository/org/apache/logging/log4j/log4j-to-slf4j/2.13.2/log4j-to-slf4j-2.13.2.jar:/root/.m2/repository/org/apache/logging/log4j/log4j-api/2.13.2/log4j-api-2.13.2.jar:/root/.m2/repository/org/slf4j/jul-to-slf4j/1.7.30/jul-to-slf4j-1.7.30.jar:/root/.m2/repository/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar:/root/.m2/repository/com/github/ulisesbocchio/jasypt-spring-boot/2.0.0/jasypt-spring-boot-2.0.0.jar:/root/.m2/repository/org/springframework/experimental/spring-graalvm-native/0.7.0/spring-graalvm-native-0.7.0.jar:/tmp/pass-generator/target/pass-generator-0.0.1-stg-SNAPSHOT.jar --allow-incomplete-classpath --no-fallback -H:+ReportExceptionStackTraces --initialize-at-build-time=org.springframework.util.unit.DataSize -H:+TraceClassInitialization --no-server -R:MaxHeapSize=16g -J-Xmx16G -H:Class=com.my.passgenerator.PassGeneratorApplication
    [com.my.passgenerator.passgeneratorapplication:1026375]    classlist:   3,609.05 ms,  1.63 GB
     ____             _               _____          _                  
    / ___| _ __  _ __(_)_ __   __ _  |  ___|__  __ _| |_ _   _ _ __ ___ 
    \___ \| '_ \| '__| | '_ \ / _` | | |_ / _ \/ _` | __| | | | '__/ _ \
     ___) | |_) | |  | | | | | (_| | |  _|  __/ (_| | |_| |_| | | |  __/
    |____/| .__/|_|  |_|_| |_|\__, | |_|  \___|\__,_|\__|\__,_|_|  \___|
          |_|                 |___/                                     

    Feature operating in FEATURE mode
    Removing unused configurations
    Use -Dspring.native.verbose=true on native-image call to see more detailed information from the feature
    [com.my.passgenerator.passgeneratorapplication:1026375]        (cap):     872.48 ms,  1.63 GB
    Found #6 types in static reflection list to register
    Skipping #6 types not on the classpath
    Attempting proxy registration of #19 proxies
    Skipped registration of #17 proxies - relevant types not on classpath
    [com.my.passgenerator.passgeneratorapplication:1026375]        setup:   2,094.23 ms,  1.63 GB
    Registering resources - #35 patterns
    Registering resources - #2 bundles
    Processing META-INF/spring.factories files...
    spring.factories processing, problem adding access for key org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer: javax/validation/ValidationException
    Processing spring.factories - ApplicationListener lists #10 application listeners
    Processing spring.factories - PropertySourceLoader lists #2 property source loaders
    spring.factories processing, problem adding access for key org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer: org/springframework/jdbc/CannotGetJdbcConnectionException
    Processing spring.factories - ApplicationListener lists #0 application listeners
    Processing spring.factories - EnableAutoConfiguration lists #127 configurations
    Excluding 115 auto-configurations from spring.factories file
    Processing spring.factories - ApplicationListener lists #1 application listeners
    Processing spring.factories - ApplicationListener lists #1 application listeners
    Found no META-INF/spring.components -> synthesizing one...
    Computed spring.components is 
    vvv
    ^^^
    Registered 0 entries
    Configuring initialization time for specific types and packages:
    #87 buildtime-init-classes   #23 buildtime-init-packages   #33 runtime-init-classes    #1 runtime-init-packages

    Warning: class initialization of class org.springframework.boot.validation.MessageInterpolatorFactory failed with exception java.lang.NoClassDefFoundError: javax/validation/ValidationException. This class will be initialized at run time because option --allow-incomplete-classpath is used for image building. Use the option --initialize-at-run-time=org.springframework.boot.validation.MessageInterpolatorFactory to explicitly request delayed initialization of this class.
    Number of types dynamically registered for reflective access: #856
    [com.my.passgenerator.passgeneratorapplication:1026375]     (clinit):     503.31 ms,  4.40 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]   (typeflow):  10,414.71 ms,  4.40 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]    (objects):  11,721.04 ms,  4.40 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]   (features):   2,246.52 ms,  4.40 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]     analysis:  25,801.80 ms,  4.40 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]     universe:     815.05 ms,  4.40 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]      (parse):   1,752.35 ms,  4.40 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]     (inline):   1,700.91 ms,  5.03 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]    (compile):  15,841.57 ms,  7.29 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]      compile:  20,640.83 ms,  7.29 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]        image:   2,280.36 ms,  7.31 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]        write:     373.32 ms,  7.31 GB
    [com.my.passgenerator.passgeneratorapplication:1026375]      [total]:  61,399.55 ms,  7.31 GB
    [INFO] 
    [INFO] --- spring-boot-maven-plugin:2.3.0.RELEASE:repackage (repackage) @ pass-generator ---
    [INFO] Replacing main artifact with repackaged archive
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 01:04 min
    [INFO] Finished at: 2020-06-13T16:54:19+08:00
    [INFO] Final Memory: 49M/1304M
    [INFO] ------------------------------------------------------------------------
    You have new mail in /var/spool/mail/root
    [root@hostserver pass-generator]# ./target/com.my.passgenerator.passgeneratorapplication 
    2020-06-13 16:54:32.506 ERROR 1030001 --- [           main] o.s.boot.SpringApplication               : Application run failed

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'passGeneratorApplication': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.my.passgenerator.PassGeneratorApplication]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.my.passgenerator.PassGeneratorApplication.()
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[na:na]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[na:na]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[na:na]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[na:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[com.my.passgenerator.passgeneratorapplication:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[com.my.passgenerator.passgeneratorapplication:na]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[com.my.passgenerator.passgeneratorapplication:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[com.my.passgenerator.passgeneratorapplication:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[com.my.passgenerator.passgeneratorapplication:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[com.my.passgenerator.passgeneratorapplication:na]
        at com.my.passgenerator.PassGeneratorApplication.main(PassGeneratorApplication.java:29) [com.my.passgenerator.passgeneratorapplication:na]
    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.my.passgenerator.PassGeneratorApplication]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.my.passgenerator.PassGeneratorApplication.()
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83) ~[na:na]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312) ~[na:na]
        ... 17 common frames omitted
    Caused by: java.lang.NoSuchMethodException: com.my.passgenerator.PassGeneratorApplication.()
        at java.lang.Class.getConstructor0(DynamicHub.java:3082) ~[na:na]
        at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2178) ~[na:na]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78) ~[na:na]
        ... 18 common frames omitted

1 个答案:

答案 0 :(得分:1)

compile.sh脚本构建方法切换到native-image-maven-plugin described in this so answer时遇到了同样的错误。这里的关键错误是No default constructor found消息,并且问题在Spring Feature在native-image-maven-plugin执行内部工作时发生:

Found no META-INF/spring.components -> synthesizing one...
    Computed spring.components is 
    vvv
    ^^^
    Registered 0 entries
    Configuring initialization time for specific types and packages:
    #87 buildtime-init-classes   #23 buildtime-init-packages   #33 runtime-init-classes 

Spring在运行时很大程度上依赖于类路径扫描,在该位置通常可以找到您的@SpringBootApplication@Component带注释的组件。但是,要使Spring应用程序与GraalVM Native Image一起使用存在很大的挑战,因为此处不再可能进行运行时类路径扫描。

Spring Feature spring-graalvm-native因此尝试处理META-INF/spring.components文件或在内存中进行计算。后者现在无法使用native-image-maven-plugin使用。要解决此问题,您需要在pom.xml中将显式依赖项添加到spring-context-indexer(请参见a fully working example here):

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-indexer</artifactId>
    </dependency>

我们应该使用的current Spring Feature docs also tell us about this dependency。如果您将spring-context-indexer添加到pom.xml,它将创建一个文件target/classes/META_INF/spring.components,其中包含您的@SpringBootApplication注释类:

com.my.passgenerator.PassGeneratorApplication=org.springframework.stereotype.Component

您的构建输出也应说明该文件已被处理,并且条目的注册是这样的:

Processing META-INF/spring.components files...
Registered 1 entries
Configuring initialization time for specific types and packages:
#87 buildtime-init-classes   #23 buildtime-init-packages   #33 runtime-init-classes

如果添加更多的@Component带注释的类,则文件还将包含它们,并且还将在native-image构建过程中注册。成功完成Maven构建后,您的Spring Boot本机应用程序应按预期启动。有关更多信息,您还可以查看this blog post about using the native-image-maven-plugin for Spring Boot GraalVM Native Image builds