Affects: 6.0.12 (spring boot 3.1.x)
I recently upgraded my project to use Spring Boot 3.1.x(from 3.0.x) and I am getting an error when trying to build a native image. The stack from the build error is
[creator] Error: Classes that should be initialized at run time got initialized during image building:
[creator] org.apache.commons.logging.LogFactory was unintentionally initialized at build time. org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService caused initialization of this class with the following trace:
[creator] at org.apache.commons.logging.LogFactory.<clinit>(LogFactory.java:136)
[creator] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Unknown Source)
[creator] at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
[creator] at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[creator] at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
[creator] at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
[creator] at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347)
[creator] at java.lang.Class.newInstance(Class.java:645)
[creator] at org.apache.commons.logging.LogFactory.createFactory(LogFactory.java:1047)
[creator] at org.apache.commons.logging.LogFactory$2.run(LogFactory.java:960)
[creator] at java.security.AccessController.executePrivileged(AccessController.java:776)
[creator] at java.security.AccessController.doPrivileged(AccessController.java:318)
[creator] at org.apache.commons.logging.LogFactory.newFactory(LogFactory.java:957)
[creator] at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:552)
[creator] at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
[creator] at org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.<clinit>(HandshakeWebSocketService.java:100)
In my sample repo I am getting this error by adding implementation("com.twilio.sdk:twilio:9.12.0")
. The library must be using the spring websockets which cause this error. Let me know if since I can only repo it by using another library if I will need to figure out another way to repro purely using HandshakeWebSocketService
Comment From: sdeleuze
This error looks similar to the one discussed in https://github.com/spring-projects/spring-framework/issues/30575, in order to fix it, you should exclude the transitive dependency on commons-logging:commons-logging
. After discussing with @snicoll, I have created https://github.com/spring-projects/spring-boot/issues/37890 to see if we could have such exclude done automatically by Spring Boot or not.