Spring Framework Technology & Digital Applications 5 — Questions and Answers
Question 1: What does the @EnableWebSecurity annotation do in a Spring Security application?
- Enables HTTPS enforcement across all endpoints
- Activates Spring Security's web security support and the Spring Security filter chain (Correct answer)
- Configures CORS policies for all REST controllers
- Generates an auto-configured login form at /login
Correct answer: Activates Spring Security's web security support and the Spring Security filter chain
@EnableWebSecurity imports Spring Security's WebSecurityConfiguration and enables the default filter chain for securing HTTP requests.
Question 2: In Spring Data JPA, what does a derived query method like findByEmailAndActive(String email, boolean active) do?
- Executes a native SQL query defined in the method body
- Generates a JPQL query from the method name at runtime (Correct answer)
- Requires a @Query annotation to define the SQL
- Calls a stored procedure named findByEmailAndActive
Correct answer: Generates a JPQL query from the method name at runtime
Spring Data parses the method name and automatically generates the corresponding JPQL query, eliminating boilerplate query code.
Question 3: Which Spring Boot testing slice annotation loads only the web layer components for MVC controller tests?
- @SpringBootTest(webEnvironment = MOCK)
- @WebMvcTest (Correct answer)
- @DataJpaTest
- @JsonTest
Correct answer: @WebMvcTest
@WebMvcTest loads only the MVC slice—controllers, filters, converters—without the full application context, making controller tests faster.
Question 4: What is the role of ApplicationContext in Spring?
- A lightweight IoC container with no AOP support
- The central interface providing bean factory, events, i18n, and resource loading (Correct answer)
- A runtime representation of a single HTTP request
- A configuration class that replaces XML-based bean definitions
Correct answer: The central interface providing bean factory, events, i18n, and resource loading
ApplicationContext extends BeanFactory with enterprise features: AOP integration, event publication, internationalization, and environment abstraction.
Question 5: Which Spring Cloud project provides distributed tracing integrated with Zipkin or Brave?
- Spring Cloud Config
- Spring Cloud Sleuth (Correct answer)
- Spring Cloud Gateway
- Spring Cloud Bus
Correct answer: Spring Cloud Sleuth
Spring Cloud Sleuth instruments your application with trace and span IDs that are automatically propagated through logs and HTTP headers for distributed tracing.
Question 6: In Spring, what is a BeanPostProcessor used for?
- Defining bean instantiation order through dependencies
- Intercepting bean creation to modify instances before and after initialization (Correct answer)
- Registering beans discovered by component scanning
- Destroying beans when the application context closes
Correct answer: Intercepting bean creation to modify instances before and after initialization
BeanPostProcessor hooks let you inspect or modify a bean instance right after construction and before or after the initialization callback fires.
Question 7: What is the effect of setting spring.jpa.open-in-view=false in Spring Boot?
- Disables the JPA entity manager entirely for the application
- Prevents the persistence context from being held open for the entire HTTP request lifecycle (Correct answer)
- Forces all JPA queries to use read-only transactions
- Disables Hibernate's second-level cache
Correct answer: Prevents the persistence context from being held open for the entire HTTP request lifecycle
Disabling the Open Session in View pattern closes the persistence context after the service layer, preventing lazy loading in views and avoiding hidden N+1 queries.
What does the @EnableWebSecurity annotation do in a Spring Security application?