Spring Framework Professional Standards & Competencies 5 — Questions and Answers
Question 1: A Spring Boot service is deployed to multiple environments. What professional pattern ensures environment-specific beans are loaded correctly?
- Hardcoding environment checks with System.getenv()
- Using @Profile to activate beans based on the active Spring profile (Correct answer)
- Duplicating application code per environment
- Using @Conditional with a custom always-true condition
Correct answer: Using @Profile to activate beans based on the active Spring profile
@Profile activates beans only when a matching profile is set via spring.profiles.active, enabling clean environment separation.
Question 2: Which metric collection standard does Spring Boot Actuator natively support for observability in production?
- Only JMX MBeans
- Micrometer with pluggable registry backends (Prometheus, Datadog, etc.) (Correct answer)
- Log4j MDC metrics only
- Custom HTTP polling endpoints
Correct answer: Micrometer with pluggable registry backends (Prometheus, Datadog, etc.)
Spring Boot Auto-configures Micrometer, which provides a vendor-neutral metrics facade exportable to Prometheus, Datadog, and other backends.
Question 3: What professional pattern should a Spring developer use to handle failures in reactive pipelines built with Spring WebFlux?
- Wrap every Mono/Flux in try-catch blocks
- Use operators like onErrorResume, onErrorReturn, or retry on the reactive chain (Correct answer)
- Throw RuntimeException and catch in @ExceptionHandler only
- Disable error propagation globally
Correct answer: Use operators like onErrorResume, onErrorReturn, or retry on the reactive chain
Reactive error operators (onErrorResume, onErrorReturn, retry) handle errors functionally within the reactive pipeline without blocking.
Question 4: A Spring professional is reviewing a microservice that calls another service. Which pattern is recommended to prevent cascading failures?
- Unlimited retries with no delay
- Circuit Breaker pattern via Resilience4j integrated with Spring Boot (Correct answer)
- Synchronous blocking calls with long timeouts
- Catching all exceptions and returning null
Correct answer: Circuit Breaker pattern via Resilience4j integrated with Spring Boot
Resilience4j's Circuit Breaker with Spring Boot auto-configuration stops cascading failures by opening the circuit when error thresholds are exceeded.
Question 5: When writing Spring integration tests, what is the professional approach to isolating tests from a real external database?
- Use the production database for all tests
- Use an in-memory database (H2) or Testcontainers with a real DB image (Correct answer)
- Skip database tests entirely
- Mock every repository interface with static data
Correct answer: Use an in-memory database (H2) or Testcontainers with a real DB image
H2 in-memory DB is fast for simple tests, while Testcontainers provides parity with production DB engines for more accurate integration tests.
Question 6: What is the professional standard for documenting REST APIs built with Spring Boot?
- Write Word documents for each endpoint
- Use SpringDoc OpenAPI (springdoc-openapi) to auto-generate Swagger UI documentation (Correct answer)
- Comment endpoints in the source code only
- Export Postman collections as documentation
Correct answer: Use SpringDoc OpenAPI (springdoc-openapi) to auto-generate Swagger UI documentation
Springdoc-openapi reads Spring MVC annotations to auto-generate OpenAPI 3.0 specs and a Swagger UI, which is the industry standard.
Question 7: A Spring developer is setting up a CI pipeline. Which testing layer should be enforced at minimum to meet professional quality standards?
- Manual QA testing only
- Unit tests with JUnit 5 and Mockito plus integration tests with @SpringBootTest (Correct answer)
- Load testing only
- Only compile-time checks via the Java compiler
Correct answer: Unit tests with JUnit 5 and Mockito plus integration tests with @SpringBootTest
Professional Spring CI pipelines require both unit tests (JUnit 5 + Mockito) and integration tests (@SpringBootTest) to validate application behavior at multiple levels.
A Spring Boot service is deployed to multiple environments.
What professional pattern ensures environment-specific beans are loaded correctly?