Description
Description
[A clear and concise description of what the bug is.]
Configuration
Version: [2.25.0]
Operating system: [Windows Or linux]
JDK: [17]
Logs
Logging system failed to initialize using configuration from 'classpath:log4j2-demo.xml'
java.lang.IllegalStateException: Could not initialize Log4J2 logging from classpath:log4j2-demo.xml
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:273)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:242)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:236)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:58)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:223)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:335)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81)
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64)
at [email protected]/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118)
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:353)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:313)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
at io.example.showcase.MainApplication.main(MainApplication.java:19)
Caused by: java.net.ProtocolException: Protocol resource has not been enabled as an allowed protocol
at org.apache.logging.log4j.core.net.UrlConnectionFactory.createConnection(UrlConnectionFactory.java:79)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.getConfigurationSource(Log4J2LoggingSystem.java:292)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:279)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:264)
... 27 more
Reproduction
Any Spring Boot application that uses Log4j2 and is then compiled into a native image.
spring-projects/spring-boot#37152 (comment)
I didn’t find a solution in the Log4j documentation. Coincidentally, I came across someone raising a similar issue here, but unfortunately, it hasn't received any response. So I’d like to bring it up again.
In GraalVM, the jar protocol is transformed into the resource protocol. However, in org.apache.logging.log4j.core.net.UrlConnectionFactory, the default allowed protocols only include "https, file, jar", and not resource. As a result, an application that works fine in its JAR form stops working after being compiled into a native-image. Manually setting the environment variable log4j2.Configuration.allowedProtocols=resource does solve the issue.
That said, I’m not sure whether this is the right approach. Does this mean Log4j2 can’t be used out of the box with GraalVM? I'm also uncertain whether this is a support issue on Log4j2’s side or Spring Boot’s integration with Log4j. I look forward to your thoughts on this!
Metadata
Metadata
Assignees
Type
Projects
Status