Master Interview Q&A

Overview

A single consolidated Q&A across the whole track. Answer each one out loud in 60–90 seconds. If you stumble, re-read the linked chapter.


Table of contents

  1. IoC, beans & lifecycle
  2. Auto-configuration
  3. Configuration & profiles
  4. Web MVC & REST
  5. JPA & @Transactional
  6. Spring Security
  7. Testing
  8. Actuator & observability
  9. Async, scheduling & events
  10. HTTP clients
  11. Boot 3 platform & deployment
  12. Proxies & pitfalls

1. IoC, beans & lifecycle

Q: What is IoC? → Container creates and wires objects; you don’t new them.

Q: ApplicationContext vs BeanFactory?ApplicationContext adds events, resource loading, i18n, AOP, and eager singleton init.

Q: Default bean scope? → Singleton.

Q: Does singleton mean thread-safe? → No. It means one instance. Keep beans stateless.

Q: Why constructor injection? → Required deps are explicit, fields can be final, easy to new in tests.

Q: @Component vs @Bean?@Component on a class Spring instantiates; @Bean on a method that returns a third-party object you can’t annotate.

Q: @Primary vs @Qualifier?@Primary picks the default when multiple match; @Qualifier chooses by name at the injection point.

Q: Component-scan range? → Same package as @SpringBootApplication plus sub-packages.

Q: @PostConstruct vs ApplicationReadyEvent?@PostConstruct runs per bean after injection; ApplicationReadyEvent runs once when the whole context is ready.

Q: Prototype injected into singleton trap? → The singleton captures one prototype forever. Use ObjectProvider<T>.

Q: Circular dependency fix? → Refactor first. @Lazy or ObjectProvider are tactical workarounds.

→ Chapter 01.


2. Auto-configuration

Q: What does @SpringBootApplication combine?@Configuration + @EnableAutoConfiguration + @ComponentScan.

Q: Where are Boot 3 auto-config classes listed?META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.

Q: Name conditional annotations.@ConditionalOnClass, @ConditionalOnMissingBean, @ConditionalOnProperty, @ConditionalOnWebApplication.

Q: How to exclude one auto-config?@SpringBootApplication(exclude=...) or spring.autoconfigure.exclude.

Q: How to debug what auto-config did?--debug flag, or Actuator conditions endpoint.

Q: What is a starter? → A dependency that bundles libraries for one feature (web, JPA, security).

Q: If I define my own DataSource? → Boot’s @ConditionalOnMissingBean fails, so its default backs off.

→ Chapter 02.


3. Configuration & profiles

Q: @ConfigurationProperties vs @Value? → Typed prefix-binding vs single-value injection.

Q: How do profiles select files?spring.profiles.active activates application-{profile}.yml.

Q: Property source order? → CLI and env vars beat files.

Q: Where do prod secrets go? → Vault / K8s Secrets / cloud secrets manager — never committed YAML.

→ Chapter 03.


4. Web MVC & REST

Q: @RestController vs @Controller?@RestController = @Controller + @ResponseBody; returns JSON instead of view name.

Q: @Valid vs @Validated?@Valid triggers Bean Validation; @Validated enables groups and class-level method validation.

Q: Global error handling?@RestControllerAdvice with @ExceptionHandler methods.

Q: What is ProblemDetail? → Spring 6’s Java type for RFC 7807 error responses.

Q: How return 201 + Location?ResponseEntity.created(URI).body(...).

→ Chapter 04.


5. JPA & @Transactional

Q: Default propagation? → REQUIRED.

Q: REQUIRES_NEW use case? → Audit log or side work that must commit independently of the outer transaction.

Q: Why isn’t @Transactional working? → Self-invocation, private method, or bean isn’t Spring-managed.

Q: readOnly = true benefit? → Hibernate skips dirty checking and flush — cheap optimisation for queries.

Q: LazyInitializationException? → Lazy association accessed after the session closed. Extend transaction or fetch eagerly.

Q: N+1 problem? → 1 query for parents + N for children. Fix with @EntityGraph, JOIN FETCH, batching, or DTOs.

Q: Default rollback rule?RuntimeException and Error roll back; checked exceptions don’t unless you set rollbackFor.

→ Chapter 05.


6. Spring Security

Q: WebSecurityConfigurerAdapter replacement? → A SecurityFilterChain bean with the HttpSecurity lambda DSL.

Q: 401 vs 403? → Unauthenticated vs authenticated-but-not-allowed.

Q: Resource-server JWT config property?spring.security.oauth2.resourceserver.jwt.issuer-uri.

Q: When disable CSRF? → Stateless token APIs that don’t use cookie sessions.

Q: @EnableGlobalMethodSecurity replacement?@EnableMethodSecurity (Spring Security 6).

→ Chapter 06 and security/.


7. Testing

Q: @SpringBootTest vs @WebMvcTest? → Full context vs web slice only.

Q: Why does @MockBean slow the suite? → Different mocks → different context cache keys → context restarts.

Q: Testcontainers purpose? → Real Postgres/Kafka in Docker for integration tests.

Q: @DynamicPropertySource? → Inject container URLs/ports before the context refreshes.

→ Chapter 07.


8. Actuator & observability

Q: Essential endpoints?health, info, prometheus. Never expose env/beans publicly.

Q: Liveness vs readiness? → Restart vs traffic eligibility. DB belongs in readiness.

Q: Micrometer role? → Metrics facade to Prometheus, OTLP, etc.

→ Chapter 08.


9. Async, scheduling & events

Q: Why doesn’t @Async fire? → Self-invocation, or missing @EnableAsync.

Q: @TransactionalEventListener(AFTER_COMMIT)? → Side effects only run if the transaction committed — avoids the dual-write bug.

Q: @Scheduled default threading? → Single-threaded. Long jobs block others until you configure a TaskScheduler pool.

→ Chapter 09.


10. HTTP clients

Q: RestTemplate status? → Maintenance mode. Use RestClient (blocking) or WebClient (reactive).

Q: Must-set outbound HTTP settings? → Connect + read timeouts, connection pool max.

Q: When is retrying safe? → Idempotent operations only. Use idempotency keys for non-idempotent ones.

→ Chapter 10.


11. Boot 3 platform & deployment

Q: Boot 3 baseline? → Java 17+ and jakarta.*.

Q: Virtual threads flag?spring.threads.virtual.enabled=true (Java 21+).

Q: Virtual thread pitfall? → Pinning inside synchronized blocks; prefer ReentrantLock.

Q: Native image trade-off? → Fast startup, low memory; slow builds and reflection config burden.

Q: Why layered JAR for Docker? → Dependencies change rarely; layering caches them so rebuilds only ship app code.

Q: Graceful shutdown?server.shutdown=graceful so K8s SIGTERM lets in-flight requests finish.

Q: JVM heap in containers?-XX:MaxRAMPercentage=75 so the JVM respects the container’s memory limit.

→ Chapters 11 and 12.


12. Proxies & pitfalls

Q: Why does @Transactional fail on this calls? → Self-invocation bypasses the proxy.

Q: proxyBeanMethods = false risk?@Bean methods calling each other no longer return singletons.

Q: final class with CGLIB? → CGLIB can’t subclass final; proxy fails.

Q: @Cacheable + @Transactional order? → Aspect order matters; verify which runs first (default is usually transaction → cache).

→ Chapter 13.


Drill protocol

  1. Cover the answers. Ask each question out loud in 60–90 seconds.
  2. Re-read the linked chapter when you stumble — don’t memorise, understand.
  3. For senior loops, prepare two production stories:
    • One performance story (e.g. fixing an N+1 or a thread pool starvation).
    • One reliability story (e.g. fixing a self-invocation @Transactional bug, or moving DB checks from liveness to readiness).

References


Happy Learning

You have finished the Spring Boot track. Drill Master Interview Q&A again before onsites, or continue with Java and Design Patterns.