Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sehmusaydogdu opened this issue Aug 12, 2024 · 4 comments
Open

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

sehmusaydogdu opened this issue Aug 12, 2024 · 4 comments
Labels

Comments

@sehmusaydogdu
Copy link

sehmusaydogdu commented Aug 12, 2024

Describe the bug

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.

<dependency>
	<groupId>org.springframework.cloud</groupId>
	<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
<dependency>
	<groupId>io.pivotal.spring.cloud</groupId>
	<artifactId>spring-cloud-services-starter-config-client</artifactId>
</dependency>

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.3
Spring Cloud Services Dependencies =4.1.5

:: 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?

Detailed information:
My application name is "micro-application". But by default "application" is loaded first and I think you get 401 for that.

config-server-401

Reproduction steps

Spring Boot v2.7.11 is success. Everything is ok.
But I saw a 401 problem in the Spring Boot v3.3.2 update.

Expected behavior

I expected no 401 messages.

Additional context

No response

@kvmw
Copy link
Contributor

kvmw commented Aug 13, 2024

@sehmusaydogdu can you share your app configuration? Are you passing SPRING_CONFIG_IMPORT as env variable?

@sehmusaydogdu
Copy link
Author

@kvmw We use the platfrom PAS (Platform As a Services). We do not use SPRING_CONFIG_IMPORT in the application. We use CF Env.

We add the Config Server name to the service section of the manifest file. When distributing to the platform, it tries to connect via CF Env and download the file.
There is only "spring.application.name: micro-application" value in the bootstrap yml file.

Dependency version info:
Spring Boot = v3.3.2

<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-bootstrap</artifactId>
	</dependency>
	<dependency>
		<groupId>io.pivotal.spring.cloud</groupId>
		<artifactId>spring-cloud-services-starter-config-client</artifactId>
	</dependency>
</dependencies>
<dependencyManagement>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-dependencies</artifactId>
			<version>2023.0.3</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
		<dependency>
			<groupId>io.pivotal.spring.cloud</groupId>
			<artifactId>spring-cloud-services-dependencies</artifactId>
			<version>4.1.5</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
	</dependencies>
</dependencyManagement>

My application name is “micro-application”. But by default loading is “application”. Why loading by default “application”?
There is no such situation in Spring Boot v2.7.11. Has anything changed with Spring Boot v3.3.2?

Spring Boot v3.3.2 Console log:
image

Spring Boot v2.7.11 Console log:

image

@kvmw
Copy link
Contributor

kvmw commented Aug 15, 2024

@sehmusaydogdu Do you have any particular reason or requirement to enable bootstrap (the old approach)?

If not, remove the dependency ( spring-cloud-starter-bootstrap ) and bootstrap.yml. Add the application name to application.properties/yaml and try again.

@sehmusaydogdu
Copy link
Author

@kvmw I deleted the bootstrap.yml file and the spring-cloud-starter-bootstrap dependency.
I added the application.yml file.

I saw that the 401 error was gone, but I couldn't understand why it said fetching config twice.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants