Running native image compilation with Spring Boot 3.x results in the following build-time error message:
Error: Classes that should be initialized at run time got initialized during image building:
org.apache.commons.logging.LogFactory was unintentionally initialized at build time. To see why org.apache.commons.logging.LogFactory got initialized use --trace-class-initialization=org.apache.commons.logging.LogFactory
org.apache.commons.logging.LogFactoryService was unintentionally initialized at build time. org.springframework.web.servlet.mvc.method.annotation.ReactiveTypeHandler caused initialization of this class with the following trace:
at org.apache.commons.logging.LogFactoryService.<clinit>(LogFactoryService.java)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Unknown Source)
at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347)
at java.lang.Class.newInstance(Class.java:645)
at org.apache.commons.logging.LogFactory.createFactory(LogFactory.java:1047)
at org.apache.commons.logging.LogFactory$2.run(LogFactory.java:960)
at java.security.AccessController.executePrivileged(AccessController.java:776)
at java.security.AccessController.doPrivileged(AccessController.java:318)
at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:957)
at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:552)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
at org.springframework.web.servlet.mvc.method.annotation.ReactiveTypeHandler.<clinit>(ReactiveTypeHandler.java:88)
Adding --initialize-at-build-time=org.apache.commons.logging.LogFactory addresses this issue. It was added in the experimental spring-native project (https://github.com/spring-attic/spring-native/commit/26ce53ac379c92ee5c6c8899f64798f25607eb04) but seems to have been removed with the GA support. Was this an intentional change?
Comment From: wilkinsona
ReactiveTypeHandler is part of Spring Framework. Can you please open a Spring Framework issue for this providing some more details about your application and how you're building the native image?
Comment From: mpeddada1
Thank you @wilkinsona! Ported this issue to https://github.com/spring-projects/spring-framework/issues/30406 with a reproducer.