Spring Framework Professional Standards & Competencies 3 — Questions and Answers
Question 1: A Spring professional wants to apply cross-cutting concerns like logging without modifying business logic. Which approach is standard?
- Subclassing every service
- Using Spring AOP with @Aspect and @Around advice (Correct answer)
- Adding logic to each controller manually
- Using @Transactional only
Correct answer: Using Spring AOP with @Aspect and @Around advice
Spring AOP with @Aspect enables modular cross-cutting concerns like logging, security, and transactions without altering business classes.
Question 2: What is the professional standard for managing database transactions in a Spring service layer?
- Manual JDBC commit/rollback calls
- @Transactional annotation on service methods (Correct answer)
- Programmatic TransactionTemplate only
- Rely on auto-commit mode
Correct answer: @Transactional annotation on service methods
@Transactional declaratively demarcates transaction boundaries, keeping business logic clean and consistent.
Question 3: Which interface should a Spring developer implement when custom initialization logic is needed after all dependencies are injected?
- BeanFactoryPostProcessor
- InitializingBean (afterPropertiesSet) (Correct answer)
- ApplicationListener
- DisposableBean
Correct answer: InitializingBean (afterPropertiesSet)
InitializingBean.afterPropertiesSet() is called by Spring after dependency injection is complete, making it the correct hook for post-injection setup.
Question 4: A developer needs to write an integration test that loads the full Spring application context. Which annotation set is the professional standard?
- @UnitTest + @Mock
- @SpringBootTest + @AutoConfigureMockMvc (Correct answer)
- @WebMvcTest only for all layers
- @ContextConfiguration alone
Correct answer: @SpringBootTest + @AutoConfigureMockMvc
@SpringBootTest loads the complete application context and @AutoConfigureMockMvc wires MockMvc for full integration testing.
Question 5: Which Spring Security configuration approach is considered the current professional standard after the deprecation of WebSecurityConfigurerAdapter?
- Extending WebSecurityConfigurerAdapter
- Declaring SecurityFilterChain beans in a @Configuration class (Correct answer)
- Using XML security namespace
- Annotating controllers with @Secured only
Correct answer: Declaring SecurityFilterChain beans in a @Configuration class
Since Spring Security 5.7, the recommended practice is to expose SecurityFilterChain @Bean methods instead of extending WebSecurityConfigurerAdapter.
Question 6: What is the professional recommendation for handling checked exceptions in Spring @Service methods?
- Swallow all exceptions silently
- Wrap in RuntimeException or define custom unchecked exceptions (Correct answer)
- Declare throws on every method signature
- Log and re-throw as Error
Correct answer: Wrap in RuntimeException or define custom unchecked exceptions
Spring's transaction and exception handling infrastructure works best with unchecked exceptions, so converting checked exceptions is a common professional standard.
Question 7: Which tool is the professional standard for building and managing dependencies in a Spring Boot project?
- Ant with Ivy
- Maven or Gradle with the Spring Boot BOM/plugin (Correct answer)
- Manual JAR management
- OSGi bundle manager
Correct answer: Maven or Gradle with the Spring Boot BOM/plugin
Maven or Gradle with the Spring Boot BOM ensures compatible dependency versions and simplifies plugin configuration for Spring projects.
A Spring professional wants to apply cross-cutting concerns like logging without modifying business logic.
Which approach is standard?