Spring Cloud Spring Cloud Configuration Management 1 — Questions and Answers
Question 1: What is the primary purpose of Spring Cloud Config Server?
- To manage service-to-service authentication
- To provide externalized configuration for distributed systems from a central place (Correct answer)
- To route HTTP requests between microservices
- To aggregate logs from multiple services
Correct answer: To provide externalized configuration for distributed systems from a central place
Spring Cloud Config Server exposes a REST API that microservices use to fetch their configuration from a central source such as a Git repository.
Question 2: Which annotation enables a Spring Boot application to function as a Spring Cloud Config Server?
- @EnableConfigClient
- @EnableCloudConfig
- @EnableConfigServer (Correct answer)
- @EnableRemoteConfig
Correct answer: @EnableConfigServer
@EnableConfigServer added to the main class activates Spring Cloud Config Server auto-configuration and exposes the configuration REST endpoints.
Question 3: By default, where does Spring Cloud Config Server look for configuration files?
- A local filesystem directory named /config
- A Git repository specified by spring.cloud.config.server.git.uri (Correct answer)
- A relational database table named CONFIG
- An environment variable named SPRING_CONFIG_LOCATION
Correct answer: A Git repository specified by spring.cloud.config.server.git.uri
The default backend for Spring Cloud Config Server is a Git repository, configured via spring.cloud.config.server.git.uri.
Question 4: What URL pattern does a Spring Cloud Config Server expose to serve configuration for a service named 'payments' in the 'production' profile?
- /payments/production (Correct answer)
- /config/payments-production
- /payments-production.yml
- /api/config?service=payments&profile=production
Correct answer: /payments/production
Config Server follows the pattern /{application}/{profile}[/{label}], so /payments/production returns the production configuration for the payments service.
Question 5: Which Spring Cloud Config feature allows a running service to refresh its configuration without restarting?
- Hot-swap reloading via JVM agent
- Spring Cloud Bus with /actuator/refresh or /actuator/bus-refresh (Correct answer)
- Kubernetes ConfigMap rolling update
- Environment variable substitution at runtime
Correct answer: Spring Cloud Bus with /actuator/refresh or /actuator/bus-refresh
Triggering /actuator/refresh (or /actuator/bus-refresh via Spring Cloud Bus) reloads @ConfigurationProperties and @Value beans marked with @RefreshScope without restarting the JVM.
Question 6: What does the `@RefreshScope` annotation do in a Spring Cloud application?
- Marks a bean to be re-created when a refresh event is received (Correct answer)
- Enables distributed tracing for the annotated component
- Registers the bean with the discovery server on startup
- Creates a new thread pool scoped to each refresh cycle
Correct answer: Marks a bean to be re-created when a refresh event is received
@RefreshScope creates a proxy bean that is lazily re-initialized from the application context when an EnvironmentChangeEvent or RefreshEvent is published.
What is the primary purpose of Spring Cloud Config Server?