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)

Solution: Adding --initialize-at-build-time=org.apache.commons.logging.LogFactory addresses this issue.

Reproducer: https://github.com/mpeddada1/spring-logging-reproducer

It was added in the experimental spring-native project (https://github.com/spring-attic/spring-native/commit/26ce53ac379c92ee5c6c8899f64798f25607eb04) but seems to not be present in the GA support. Was this an intentional change?

Comment From: sdeleuze

This is caused by the commons-logging which is conflicting with spring-jcl. Also notice that refresh scope is not supported with AOT/native as documented here.

When removing commons-logging and refresh scope, the native compilation works as expected.

Comment From: phejl

@sdeleuze This started appearing after the upgrade from 3.0.5 to 3.1.0 (app was otherwise unchanged). Indeed there is (transitive) commons-logging in the dependencies. Is it worth reporting or is it just the same thing in different context? After module substitution (commong-logging -> spring-jcl) compilation succeeds.

Comment From: sdeleuze

Could you please share which dependency is bringing commons-logging transitively?