Versions:
spring-boot-starter-parent : 3.3.2 spring-cloud-dependencies: 2023.0.3 jdk: 21
Details:
My "Spring Cloud Config Server" has a security configuration applied, therefore authentication is required to access the service.
spring:
security:
user:
name: root
password: password
The source code can be seen at https://github.com/luidoc/demo-config-server-native.git
On the other hand, I have a sample application that uses the "Spring Cloud Config Server" service, both to obtain its configuration file and to obtain the log4j2 configuration file (log4j2-spring.xml). The source code can be seen at https://github.com/luidoc/config-server-client.git
Below I show the bootstrap.yml configuration file:
spring:
main:
allow-bean-definition-overriding: true
profiles:
active: dev
application:
name: config-server-client
config:
import: optional:configserver=${spring.cloud.config.url}
cloud:
config:
url: http://localhost:8888
uri: http://localhost:8888
username: root
password: 'password'
name: ${spring.application.name}
profile: dev
label: main
logging:
config: ${spring.cloud.config.url}/${spring.application.name}/${spring.cloud.config.profile}/${spring.cloud.config.label}/log4j2-spring.xml?resolvePlaceholders=false
log4j2:
Configuration:
allowedProtocols: 'http,https'
When running the sample application, it fails to obtain the log4j2 configuration file from the "Config Server" service, resulting in an http 401 error.
The error trace can be seen below:
java -jar .\target\config-server-client.jar
Logging system failed to initialize using configuration from 'http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false'
java.lang.IllegalStateException: Could not initialize Log4J2 logging from http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:198)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:246)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:238)
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:225)
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.initialize(Log4j2SpringBootLoggingSystem.java:96)
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 java.base/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:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:195)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77)
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 java.base/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:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
at com.example.demo.ConfigServerClientApplication.main(ConfigServerClientApplication.java:10)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1998)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599)
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.getConfigurationSource(Log4j2SpringBootLoggingSystem.java:247)
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:159)
... 48 more
18:44:35.385 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: java.lang.IllegalStateException: Could not initialize Log4J2 logging from http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:347) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64) ~[spring-boot-3.3.2.jar!/:3.3.2]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:370) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:195) ~[spring-cloud-context-4.1.4.jar!/:4.1.4]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114) ~[spring-cloud-context-4.1.4.jar!/:4.1.4]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77) ~[spring-cloud-context-4.1.4.jar!/:4.1.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64) ~[spring-boot-3.3.2.jar!/:3.3.2]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) [?:?]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:370) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) [spring-boot-3.3.2.jar!/:3.3.2]
at com.example.demo.ConfigServerClientApplication.main(ConfigServerClientApplication.java:10) [!/:1.0.0-SNAPSHOT]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91) [config-server-client.jar:1.0.0-SNAPSHOT]
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53) [config-server-client.jar:1.0.0-SNAPSHOT]
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58) [config-server-client.jar:1.0.0-SNAPSHOT]
Caused by: java.lang.IllegalStateException: Could not initialize Log4J2 logging from http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:198) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:246) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:238) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:58) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:225) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.initialize(Log4j2SpringBootLoggingSystem.java:96) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:335) ~[spring-boot-3.3.2.jar!/:3.3.2]
... 41 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1998) ~[?:?]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599) ~[?:?]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.getConfigurationSource(Log4j2SpringBootLoggingSystem.java:247) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:159) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:246) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:238) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:58) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:225) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.initialize(Log4j2SpringBootLoggingSystem.java:96) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:335) ~[spring-boot-3.3.2.jar!/:3.3.2]
... 41 more
18:44:35.412 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: java.lang.IllegalStateException: Could not initialize Log4J2 logging from http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:347) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:298) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64) ~[spring-boot-3.3.2.jar!/:3.3.2]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:370) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:195) ~[spring-cloud-context-4.1.4.jar!/:4.1.4]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114) ~[spring-cloud-context-4.1.4.jar!/:4.1.4]
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77) ~[spring-cloud-context-4.1.4.jar!/:4.1.4]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) ~[spring-context-6.1.11.jar!/:6.1.11]
at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64) ~[spring-boot-3.3.2.jar!/:3.3.2]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:370) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) [spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) [spring-boot-3.3.2.jar!/:3.3.2]
at com.example.demo.ConfigServerClientApplication.main(ConfigServerClientApplication.java:10) [!/:1.0.0-SNAPSHOT]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[?:?]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[?:?]
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91) [config-server-client.jar:1.0.0-SNAPSHOT]
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53) [config-server-client.jar:1.0.0-SNAPSHOT]
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58) [config-server-client.jar:1.0.0-SNAPSHOT]
Caused by: java.lang.IllegalStateException: Could not initialize Log4J2 logging from http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:198) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:246) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:238) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:58) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:225) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.initialize(Log4j2SpringBootLoggingSystem.java:96) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:335) ~[spring-boot-3.3.2.jar!/:3.3.2]
... 41 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1998) ~[?:?]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599) ~[?:?]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.getConfigurationSource(Log4j2SpringBootLoggingSystem.java:247) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:159) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:246) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:238) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:67) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:58) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:225) ~[spring-boot-3.3.2.jar!/:3.3.2]
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.initialize(Log4j2SpringBootLoggingSystem.java:96) ~[log4j-spring-boot-2.23.1.jar!/:2.23.1]
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:335) ~[spring-boot-3.3.2.jar!/:3.3.2]
... 41 more
On the other hand, I can perfectly obtain the configuration file using curl.
curl --location 'http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false' \
--header 'Authorization: Basic cm9vdDpwYXNzd29yZA=='
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg %n" />
</Console>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
Sample
Config Server: https://github.com/luidoc/demo-config-server-native.git Demo application: https://github.com/luidoc/config-server-client.git
Comment From: ryanjbaxter
The configuration to access the config server and the configuration on where to get your logging file from are separate and have no impact on each other. Have you tried
logging:
config: https://${spring.cloud.config.username}:${spring.cloud.config.password}@host:port/${spring.application.name}/${spring.cloud.config.profile}/${spring.cloud.config.label}/log4j2-spring.xml?resolvePlaceholders=false
Comment From: luidoc
Yes, I've tried that before, but it doesn't work. As you can see, an error occurs (error 401):
Logging system failed to initialize using configuration from 'http://root:password@localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false'
java.lang.IllegalStateException: Could not initialize Log4J2 logging from http://root:password@localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:198)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.load(Log4J2LoggingSystem.java:246)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:238)
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:225)
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.initialize(Log4j2SpringBootLoggingSystem.java:96)
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 java.base/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:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:195)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)
at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77)
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 java.base/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:370)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352)
at com.example.demo.ConfigServerClientApplication.main(ConfigServerClientApplication.java:10)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://root:password@localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1998)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1599)
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.getConfigurationSource(Log4j2SpringBootLoggingSystem.java:247)
at org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem.loadConfiguration(Log4j2SpringBootLoggingSystem.java:159)
... 43 more
The server treats this call as if it were an anonymous access, as you can see in the log:
TRACE 1144 --- [nio-8888-exec-1] o.s.s.w.a.ExceptionTranslationFilter : Sending AnonymousAuthenticationToken [Principal=anonymousUser, Credentials=[PROTECTED], Authenticated=true, Details=WebAuthenticationDetails [RemoteIpAddress=127.0.0.1, SessionId=null], Granted Authorities=[ROLE_ANONYMOUS]] to authentication entry point since access is denied
org.springframework.security.access.AccessDeniedException: Access Denied
at org.springframework.security.web.access.intercept.AuthorizationFilter.doFilter(AuthorizationFilter.java:98) ~[spring-security-web-6.3.1.jar!/:6.3.1]
Comment From: ryanjbaxter
Can you authenticate and access the file in other ways?
Comment From: luidoc
I don't quite understand your question, if you mean if the file can be accessed from spring cloud config server url, yes, it is possible. If you run the example you will see that you can run a
curl --location 'http://localhost:8888/config-server-client/dev/main/log4j2-spring.xml?resolvePlaceholders=false' --header 'Authorization: Basic cm9vdDpwYXNzd29yZA=='
And you will get the content of the file as a response. In fact, if in the example of spring cloud config server I disable security or add this to the spring security filter of the server:
.requestMatchers(new AntPathRequestMatcher("/**/**/**/log4j2.xml**")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/**/**/**/log4j2-spring.xml**")).permitAll()
everything works correctly. I think the problem is in org.apache.logging.log4j.spring.boot.Log4j2SpringBootLoggingSystem , specifically in the getConfigurationSource method, that does not obtain the spring cloud config security configuration.
Comment From: ryanjbaxter
I wouldn't expect Boot to know anything about the security credentials for fetching remote logging configuration. I would expect their to be a separate configuration for the Boot to fetch the remote logging configuration (if they support such a thing). I don't think this is a Spring Cloud Config problem.
Comment From: spring-cloud-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: luidoc
Please, would you be so kind as to let me know what information you are missing in order to evaluate this issue? I have clearly indicated the problem, the versions, as well as provided the URL of the examples to reproduce the problem.
Comment From: ryanjbaxter
As I said above
I don't think this is a Spring Cloud Config problem.
Comment From: luidoc
After reviewing the log4j documentation, I have seen that according to what is indicated in https://logging.apache.org/log4j/2.x/manual/configuration.html the credentials are specified with the properties log4j2.Configuration.username and log4j2.Configuration.password.
I have modified the example (https://github.com/luidoc/config-server-client.git) so that anyone who has the same problem can see how to solve it.