spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.97k stars 1.29k forks source link

Getting Config Server 401 error during Spring 3.X update #2448

Closed sehmusaydogdu closed 3 months ago

sehmusaydogdu commented 3 months ago

We are updating Spring Boot 2.7.11 to 3.X. We use Config Server to manage config files. We encountered a problem like this.

The problem: You can see that it does fetch config from server twice in the application log. The application can successfully read data from the Config Server when it starts up with Spring Boot 2.7.11. While the application is starting up with Spring Boot 3, it tries to fetch data twice while trying to read data from the Config Server. When trying to bring it first, it gets a 401 error. The second attempt also gets up successfully without any errors.

The dependency we use is as follows.

org.springframework.cloud spring-cloud-starter-bootstrap io.pivotal.spring.cloud spring-cloud-services-starter-config-client

Spring Boot = v2.7.11 Spring Cloud Dependencies = 2021.0.6 Spring Cloud Services Dependencies = 3.5.4

:: Spring Boot :: (v2.7.11) 2024-08-09 09:47:35.623 INFO 17060 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : https://config-server-XXXXXX.com.tr 2024-08-09 09:47:36.055 INFO 17060 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=micro-application, profiles=[default], label=tst, version=null, state=null 2024-08-09 09:47:36.056 INFO 17060 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-credhub-micro-application-default-tst'}, BootstrapPropertySource {name='bootstrapProperties-ssh://mirror@XXXXXXXXXX/var/vcap/store/mirror/1111111111111111111111111/config-server/micro-application.yml'}] 2024-08-09 09:47:36.076 INFO 17060 --- [ main] c.ykb.architecture.services.Application : No active profile set, falling back to 1 default profile: "default" 2024-08-09 09:47:36.101 INFO 17060 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : https://config-server-XXXXXX.com.tr 2024-08-09 09:47:36.101 INFO 17060 --- [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Located environment: name=micro-application, profiles=[default], label=tst, version=null, state=null 2024-08-09 09:47:36.729 INFO 17060 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=ee6a8da5-45f4-39a3-977f-874dcc9b7cce 2024-08-09 09:47:37.157 INFO 17060 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)

################################################################ Spring Boot = v3.3.2 Spring Cloud Dependencies = 2023.0.1 Spring Cloud Services Dependencies =4.1.2

:: Spring Boot :: (v3.3.2) 2024-08-09T17:17:06.427+03:00 INFO 14268 --- [micro-application] [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : https://config-server-XXXXXX.com.tr 2024-08-09T17:17:06.532+03:00 WARN 14268 --- [micro-application] [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: 401 Unauthorized: [no body] 2024-08-09T17:17:06.541+03:00 INFO 14268 --- [micro-application] [ main] c.ykb.architecture.services.Application : No active profile set, falling back to 1 default profile: "default" 2024-08-09T17:17:06.568+03:00 INFO 14268 --- [micro-application] [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : https://config-server-XXXXXX.com.tr 2024-08-09T17:17:06.568+03:00 INFO 14268 --- [micro-application] [ main] o.s.c.c.c.ConfigServerConfigDataLoader : Located environment: name=micro-application, profiles=[default], label=tst, version=null, state=null 2024-08-09T17:17:07.310+03:00 INFO 14268 --- [micro-application] [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=1f77964d-709d-3977-a438-235cef625e86 2024-08-09T17:17:07.747+03:00 INFO 14268 --- [micro-application] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)

To solve this problem, I wrote spring.cloud.config.enabled: false** to the bootstrap.yml file located in the src/main/resource directory and saw that the 401 error disappeared and fetch config from server *** was written once. The opening log is as follows:

:: Spring Boot :: (v3.3.2) 2024-08-09T17:22:17.230+03:00 INFO 15868 --- [micro-application] [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : https://config-server-XXXXXX.com.tr 2024-08-09T17:22:17.684+03:00 INFO 15868 --- [micro-application] [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=micro-application, profiles=[default], label=tst, version=null, state=null 2024-08-09T17:22:17.687+03:00 INFO 15868 --- [micro-application] [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-credhub-micro-application-default-tst'}, BootstrapPropertySource {name='bootstrapProperties-ssh://mirror@XXXXXXXXXXXXX/var/vcap/store/mirror/11111111111111111111111/config-server/micro-application.yml'}] 2024-08-09T17:22:30.261+03:00 INFO 15868 --- [micro-application] [ main] c.ykb.architecture.services.Application : No active profile set, falling back to 1 default profile: "default" 2024-08-09T17:22:31.361+03:00 INFO 15868 --- [micro-application] [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=1f77964d-709d-3977-a438-235cef625e86 2024-08-09T17:22:31.925+03:00 INFO 15868 --- [micro-application] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8080 (http)

Is this a correct method? Is there an alternative solution?

ryanjbaxter commented 3 months ago

I see you are using Spring Cloud Services and not the open source Spring Cloud Config project. You should open a support ticket with Spring Cloud Services and ask you question there.