In the SpringBoot3 application built by Graalvm Native Image, I use Apache Poi to depend on log4j. The construction is successful, but the following errors occur at running. How can I configure it to avoid this error?
I tested in Spring Boot 2.7.1 + Spring Native, there is no problem.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.0.0)
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.Application : Starting AOT-processed Application using Java 17.0.5 with PID 18532 (D:\work-ide\IDEA\data-server\target\data-server.exe started by westinyang in D:\work-ide\IDEA\data-server\target)
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.Application : No active profile set, falling back to 1 default profile: "default"
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-12-06T11:53:05.855+08:00 INFO 18532 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-12-06T11:53:05.889+08:00 INFO 18532 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-12-06T11:53:05.889+08:00 INFO 18532 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-06T11:53:05.889+08:00 INFO 18532 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.1]
2022-12-06T11:53:05.897+08:00 INFO 18532 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-06T11:53:05.897+08:00 INFO 18532 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 41 ms
2022-12-06T11:53:05.920+08:00 INFO 18532 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-12-06T11:53:05.921+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.Application : Started Application in 0.072 seconds (process running for 0.078)
ERROR StatusLogger Unable to load services for service class org.apache.logging.log4j.spi.Provider
java.lang.InternalError: com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining hidden classes at runtime is not supported.
at java.base@17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:413)
at java.base@17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:315)
at java.base@17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.buildCallSite(InnerClassLambdaMetafactory.java:228)
at java.base@17.0.5/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:341)
at org.apache.logging.log4j.util.ServiceLoaderUtil.loadClassloaderServices(ServiceLoaderUtil.java:93)
at org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(ServiceLoaderUtil.java:74)
at org.apache.logging.log4j.util.ServiceLoaderUtil.loadServices(ServiceLoaderUtil.java:68)
at org.apache.logging.log4j.util.ProviderUtil.<init>(ProviderUtil.java:67)
at org.apache.logging.log4j.util.ProviderUtil.lazyInit(ProviderUtil.java:145)
at org.apache.logging.log4j.util.ProviderUtil.hasProviders(ProviderUtil.java:129)
at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:90)
at org.apache.poi.util.IOUtils.<clinit>(IOUtils.java:43)
at org.apache.poi.poifs.filesystem.FileMagic.valueOf(FileMagic.java:177)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:309)
at cn.hutool.poi.excel.WorkbookUtil.createBook(WorkbookUtil.java:120)
at cn.hutool.poi.excel.WorkbookUtil.createBook(WorkbookUtil.java:70)
at cn.hutool.poi.excel.ExcelReader.<init>(ExcelReader.java:71)
at cn.hutool.poi.excel.ExcelReader.<init>(ExcelReader.java:50)
at cn.hutool.poi.excel.ExcelUtil.getReader(ExcelUtil.java:151)
at cn.hutool.poi.excel.ExcelUtil.getReader(ExcelUtil.java:127)
at com.example.dataserver.AppRunner.run(AppRunner.java:23)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:748)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at com.example.dataserver.Application.main(Application.java:13)
at java.base@17.0.5/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
at org.graalvm.nativeimage.builder/com.oracle.svm.core.windows.WindowsPlatformThreads.osThreadStartRoutine(WindowsPlatformThreads.java:178)
Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining hidden classes at runtime is not supported.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
at java.base@17.0.5/java.lang.ClassLoader.defineClass0(ClassLoader.java:338)
at java.base@17.0.5/java.lang.System$2.defineClass(System.java:2307)
at java.base@17.0.5/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2439)
at java.base@17.0.5/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClassAsLookup(MethodHandles.java:2420)
at java.base@17.0.5/java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:2127)
at java.base@17.0.5/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:407)
... 28 more
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
2022-12-06T11:53:05.981+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.AppRunner : 3
2022-12-06T11:53:05.981+08:00 INFO 18532 --- [ restartedMain] com.example.dataserver.AppRunner : Service running on 127.0.0.1:8080
pom.xml dependencies
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.10</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
I tried some solutions, but there is no effect yet,I joined the native-image parameter --initialize-at-run-time=org.apache.logging.log4j.spi.Provider
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
<configuration>
<buildArgs>
<arg>--no-fallback</arg>
<arg>--initialize-at-run-time=org.apache.logging.log4j.spi.Provider</arg>
<arg>-H:+AddAllCharsets</arg>
</buildArgs>
</configuration>
</plugin>