当前位置: 首页 > 知识库问答 >
问题:

springboot fat jar的graalvm本机映像在运行时抛出NoSuchMethodException xxx.()

窦华晖
2023-03-14

我设法为springboot fat jar构建了本机映像,但当我运行它时,它抛出了异常:“java.lang.NosuchMethodException:com.my.PassGenerator.PassGeneratorApplication. () ”。我尝试添加一个默认构造和一个空的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个答案

秦弘亮
2023-03-14

在从compile.sh脚本构建方法切换到本so答案中描述的native-image-maven-plugin时,我也遇到了同样的错误。这里的关键错误是no default constructorfound消息,问题发生在Spring特性在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本机映像是一个很大的挑战,因为运行时类路径扫描在这里已经不可能了。

因此,Spring特性spring-graalvm-native尝试处理meta-inf/Spring.components文件或在内存中计算。后者现在不能使用native-image-maven-plugin。要解决这个问题,您需要在pom.xml中向spring-context-indexer添加一个显式的依赖项(请参阅此处的一个完全工作的示例):

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

当前的Spring特性文档也告诉了我们应该使用的这种依赖关系。如果您将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原生应用程序应该按照预期启动。有关更多信息,您还可以查看这篇关于使用native-image-maven-plugin构建Spring Boot GraalVM本机映像的博文。

 类似资料:
  • 我正在尝试使用GraalVM为spring cloud gateway构建本机映像。我已经成功构建了一个可以启动的本机映像,但在第一个http请求时,我出现了以下错误: 添加此标志没有帮助 并在反射配置中添加一个条目,不是吗 该项目可以在这里找到:https://github.com/hanouard/demo-native-gateway 你知道是什么导致了这个错误吗?

  • 我正在试验在GraalVM本机映像中从Java代码运行JS脚本。 Java代码如下所示: JS代码只是通过调用对象上的一个方法来尝试使用它,例如: 当在GraalVM中运行时,这项功能有效,但当创建本机映像时,它会失败,并出现以下错误: 如果我只是像在

  • 亲爱的,我下面的原生图像构建教程由Quarkus创建原生graalvm,但我得到了下面的错误: 我的环境:OS:CentOS 7 Quarkus:0.11.0 Java:Open JDK 1.8.0_181 GraalVM:1.0.0-rc13 使用quarkus在你的应用程序中没有主要方法,但如何使用graal原生图像使其工作?

  • 在哪里可以找到使用 -H:配置文件目录设置的 GraalVM 配置文件的文档/模式

  • 我正在使用GraalVm 21.0.0.2的native-image-maven-plugin为JavaFX应用程序创建一个本机映像。当我尝试在构建成功结束后执行它时,我得到以下错误: 我很感激你能给我的任何帮助。

  • 我正在尝试用Dockers创建一个GraalVM本地映像。我已经创建了一个Micronaut项目,并成功创建了jar应用程序,并在docker中运行;此外,我已经用这个jar文件创建了一个GraalVM本机映像,现在可以运行这个应用程序,但我需要在docker中运行一个GraalVM本机映像,在论坛中寻找答案。我发现有必要在docker中构建本机映像。因此我尝试了这个docker文件: 它不会抛出