Spring Framework Technology & Digital Applications 4 — Questions and Answers
Question 1: Which Spring Cloud Netflix component acts as an API gateway and edge server?
- Hystrix
- Zuul (Correct answer)
- Eureka
- Ribbon
Correct answer: Zuul
Zuul is Netflix's edge service that provides dynamic routing, monitoring, resiliency, and security at the API gateway layer.
Question 2: What is the function of the @SpringBootTest annotation?
- Runs only unit tests without loading any Spring context
- Loads the full application context for integration testing (Correct answer)
- Mocks all beans in the context automatically
- Configures a test database for repository tests only
Correct answer: Loads the full application context for integration testing
@SpringBootTest bootstraps the full application context (or a slice of it) for integration tests, simulating the real runtime environment.
Question 3: In Spring's reactive stack, what does the Mono type represent?
- A stream of 0 to N asynchronous items
- A single asynchronous value or empty result (0 or 1 items) (Correct answer)
- A blocking future that resolves to exactly one value
- A cold observable that repeats on each subscription
Correct answer: A single asynchronous value or empty result (0 or 1 items)
Mono is Project Reactor's publisher for at most one item, analogous to CompletableFuture but composable and non-blocking.
Question 4: Which Spring annotation combines @Controller and @ResponseBody?
- @Service
- @Component
- @RestController (Correct answer)
- @RequestMapping
Correct answer: @RestController
@RestController is a convenience annotation that applies @Controller and @ResponseBody to every handler method in the class.
Question 5: What is the purpose of the @Profile annotation in Spring?
- Monitors bean performance and logs execution time
- Activates beans only when a specified environment profile is active (Correct answer)
- Groups beans by functional domain for documentation
- Restricts bean creation to the production environment only
Correct answer: Activates beans only when a specified environment profile is active
@Profile allows beans to be conditionally registered based on which Spring profiles (e.g., 'dev', 'prod') are active at runtime.
Question 6: Which Spring component is responsible for translating HTTP requests into handler method invocations?
- ViewResolver
- HandlerMapping
- DispatcherServlet
- HandlerAdapter (Correct answer)
Correct answer: HandlerAdapter
HandlerAdapter bridges the DispatcherServlet to specific handler types, invoking the correct method with resolved arguments and return value processing.
Question 7: In Spring Boot, how do you override a specific auto-configuration class?
- Delete the auto-configuration JAR from the classpath
- Use @SpringBootApplication(exclude = SomeAutoConfiguration.class) (Correct answer)
- Annotate your custom bean with @Primary only
- Set spring.autoconfigure.enabled=false in application.properties
Correct answer: Use @SpringBootApplication(exclude = SomeAutoConfiguration.class)
The exclude attribute on @SpringBootApplication (or @EnableAutoConfiguration) prevents the specified auto-configuration class from being applied.
Which Spring Cloud Netflix component acts as an API gateway and edge server?