Section 5 ยท 29 questions

Spring Spring Boot

29 interview questions and answers in the Spring Spring Boot section.

English Spring Spring Boot Source Markdown
Language versions: English Russian Ukrainian

Questions in this section

  1. What is Dependency Injection?
  2. Difference between Constructor, Setter and Field Injection
  3. Which Injection Type is Recommended and Why?
  4. What is a Bean in Spring?
  5. How to Create a Bean in Spring?
  6. What is Bean Lifecycle?
  7. What are the Bean Lifecycle Stages?
  8. What is BeanPostProcessor?
  9. What do @PostConstruct and @PreDestroy Methods Do?
  10. What is Bean Scope?
  11. What Scopes Exist in Spring?
  12. Difference between Singleton and Prototype Scope?
  13. What is a Proxy in Spring?
  14. When Does Spring Create a Proxy?
  15. What is AOP (Aspect-Oriented Programming)?
  16. What is Aspect, Advice, Pointcut, Join Point?
  17. What Does the @Transactional Annotation Do?
  18. Why @Transactional Does Not Work with Self-Invocation?
  19. How to Solve the Self-Invocation Problem?
  20. What is Auto-Configuration in Spring Boot?
  21. How @SpringBootApplication Works
  22. What is a Starter in Spring Boot?
  23. What Does the @ComponentScan Annotation Do?
  24. What is a @Configuration Class?
  25. Difference between @Component, @Service, @Repository, @Controller?
  26. What Does the @Autowired Annotation Do?
  27. What to Do If There Are Multiple Beans of the Same Type?
  28. What is @Qualifier?
  29. What are Profiles in Spring?

Study navigator

29 questions for Middle Java Developer interview preparation.


All Questions

# Question Difficulty
1 What is Dependency Injection One star
2 Difference between constructor, setter and field injection Two stars
3 Which injection type is recommended and why Two stars
4 What is a Bean in Spring Two stars
5 How to create a Bean in Spring Two stars
6 What is Bean Lifecycle Three stars
7 What are the Bean Lifecycle stages Three stars
8 What is BeanPostProcessor Three stars
9 What do @PostConstruct and @PreDestroy annotated methods do Two stars
10 What is Bean scope Two stars
11 What scopes exist in Spring Two stars
12 Difference between singleton and prototype scope Two stars
13 What is a proxy in Spring Three stars
14 When does Spring create a proxy Three stars
15 What is AOP (Aspect-Oriented Programming) Three stars
16 What is aspect, advice, pointcut, join point Three stars
17 What does the @Transactional annotation do Three stars
18 Why @Transactional does not work with self-invocation Three stars
19 How to solve the self-invocation problem Three stars
20 What is auto-configuration in Spring Boot Three stars
21 How @SpringBootApplication works Three stars
22 What is a starter in Spring Boot Two stars
23 What does the @ComponentScan annotation do Three stars
24 What is a @Configuration class Three stars
25 Difference between @Component, @Service, @Repository, @Controller Two stars
26 What does the @Autowired annotation do Two stars
27 What to do if there are multiple beans of the same type Two stars
28 What is @Qualifier Two stars
29 What are profiles in Spring Two stars

Topic Dependency Map

                    +------------------------------------------+
                    |   DI FUNDAMENTALS (1-3)                  |
                    |   1. Dependency Injection                |
                    |   2. Constructor vs Setter vs Field      |
                    |   3. Best practices                      |
                    +------------------|-----------------------+
                                       |
            +--------------------------|--------------------------+
            v                          v                          v
    +---------------+        +---------------+        +--------------------+
    | BEAN CONCEPT   |        | LIFECYCLE     |        | SCOPE              |
    | (4-5)          |        | (6-9)         |        | (10-12)            |
    | 4. Bean        |        | 6. Lifecycle  |        | 10. Scope concept  |
    | 5. Creation    |        | 7. 12 steps   |        | 11. Scope types    |
    |                |        | 8. BPP        |        | 12. Singleton vs   |
    |                |        | 9. @PostCon/  |        |     Prototype      |
    |                |        |    @PreDest   |        |                    |
    +-------+-------+        +-------+-------+        +--------+-----------+
            |                        |                        |
            +------------------------|------------------------+
                                     v
                    +------------------------------------------+
                    |   PROXY & AOP (13-19)                    |
                    |   13. Proxy (concept)                    |
                    |   14. When Spring creates proxy          |
                    |   15. AOP                                |
                    |   16. Aspect, advice, pointcut           |
                    |   17. @Transactional                     |
                    |   18-19. Self-invocation problem         |
                    +------------------------------------------+
                                     |
            +------------------------|------------------------+
            v                        v                        v
    +---------------+        +---------------+        +--------------------+
    | SPRING BOOT    |        | ANNOTATIONS   |        |                    |
    | (20-24)        |        | (25-29)       |        |                    |
    | 20. AutoConfig |        | 25. @Component |        |                    |
    | 21. @SpringBoot|        |    @Service...  |        |                    |
    | 22. Starters   |        | 26. @Autowired |        |                    |
    | 23. @CompScan  |        | 27. Multiple   |        |                    |
    | 24. @Config    |        |    beans       |        |                    |
    |                |        | 28. @Qualifier |        |                    |
    |                |        | 29. Profiles   |        |                    |
    +---------------+        +---------------+        +--------------------+

Junior Level (weeks 1-2)

Step Topic Files Goal
1 DI basics Q1, Q2, Q3 What is DI, injection types, recommendations
2 Bean concept Q4, Q5 Bean vs POJO, creation methods
3 Scope Q10, Q12 Singleton vs Prototype
4 Annotations Q25, Q26 @Component vs @Service, @Autowired
5 Spring Boot basics Q20, Q22 Auto-configuration, starters

Middle Level (weeks 3-4)

Step Topic Files Goal
1 Lifecycle Q6, Q7, Q9 Stages, @PostConstruct/@PreDestroy
2 BPP Q8 BeanPostProcessor, proxying
3 Scope types Q11 Request, Session, Application scope
4 Proxy Q13, Q14 CGLIB vs JDK Proxy, when created
5 @Transactional Q17, Q18, Q19 How it works, self-invocation
6 @SpringBootApplication Q21 Composite annotations, proxyBeanMethods
7 Bean resolution Q27, Q28, Q29 @Qualifier, @Primary, Profiles

Senior Level (weeks 5-6)

Step Topic Files Goal
1 Lifecycle deep Q7 (Senior) BPP ordering, early init, circular deps
2 AOP internals Q15, Q16 Spring AOP vs AspectJ, advice types, pointcut matching
3 @Transactional deep Q17 (Senior) Propagation, isolation, rollback rules, ConnectionReleaseMode
4 Autoconfiguration Q20, Q23 Conditional annotations, spring.factories vs .imports, @ComponentScan internals
5 @Configuration internals Q24 Full vs Lite mode, CGLIB proxy, @Bean inter-dependencies
6 Bean creation Q5 (Senior) ImportSelector, ImportBeanDefinitionRegistrar, FactoryBean, GraalVM
7 Proxy & self-invocation Q14, Q18, Q19 All 4 solutions, trade-offs, AopContext

Key Topic Connections

Topic: DI and Bean

Q1 (DI) -> Q2 (Injection types) -> Q3 (Recommendations)
     |
Q4 (Bean) -> Q5 (Creation) -> Q25 (@Component vs @Service...)

Key connections:

  • Q1 <-> Q4: DI is the principle, Bean is the object managed by the container
  • Q2 <-> Q3: Constructor injection is recommended, but there are exceptions
  • Q4 <-> Q5: Bean = concept, @Component/@Bean = creation methods
  • Q5 <-> Q23: @ComponentScan = how Spring finds @Component classes

Topic: Lifecycle and Scope

Q6 (Lifecycle) -> Q7 (12 steps) -> Q8 (BPP) -> Q9 (@PostConstruct)
     |
Q10 (Scope) -> Q11 (Scope types) -> Q12 (Singleton vs Prototype)

Key connections:

  • Q6 <-> Q8: BPP is a key lifecycle mechanism (proxying, initialization)
  • Q7 <-> Q8: BPPs are called at multiple lifecycle stages
  • Q9 <-> Q17: @PostConstruct does NOT work with @Transactional (proxy does not exist yet!)
  • Q10 <-> Q13: Request/Session scopes create proxies for injection into singleton

Topic: Proxy and AOP

Q13 (Proxy) -> Q14 (When created) -> Q15 (AOP) -> Q16 (Advice/Pointcut)
     |                                      |
Q17 (@Transactional) -> Q18 (Self-invocation) -> Q19 (Solutions)

Key connections:

  • Q13 <-> Q14: Proxy is the mechanism, Q14 explains WHEN Spring creates it
  • Q15 <-> Q17: @Transactional is the most common AOP example
  • Q17 <-> Q18: Self-invocation is the main @Transactional trap
  • Q18 <-> Q19: 4 solutions: refactoring, self-injection, TransactionTemplate, AopContext

Topic: Spring Boot and Annotations

Q20 (AutoConfig) -> Q21 (@SpringBootApplication) -> Q22 (Starters)
     |
Q23 (@ComponentScan) -> Q24 (@Configuration) -> Q25 (@Component/@Service/...)
     |
Q26 (@Autowired) -> Q27 (Multiple beans) -> Q28 (@Qualifier) -> Q29 (Profiles)

Key connections:

  • Q20 <-> Q21: @SpringBootApplication = @Configuration + @ComponentScan + @EnableAutoConfiguration
  • Q21 <-> Q24: @SpringBootConfiguration = @Configuration with proxyBeanMethods
  • Q23 <-> Q5: @ComponentScan -> ASM scanning -> BeanDefinition creation
  • Q26 <-> Q27-Q28: @Autowired -> multiple beans -> @Qualifier/@Primary

Cheat Sheet: What to Know for Each Level

Junior

  • DI = dependencies are provided from outside, not via new
  • Constructor injection is recommended, Field injection is not
  • Bean = object managed by Spring, POJO = regular object
  • @Component, @Service, @Repository, @Controller = stereotype annotations
  • @Autowired = dependency injection by type
  • Singleton = one per entire context, Prototype = new on each request
  • Spring Boot = auto-configuration + starters + embedded server

Middle

  • Bean Lifecycle: Instantiation -> Populate -> Initialize -> Ready -> Destroy
  • @PostConstruct does NOT work with @Transactional (proxy does not exist yet)
  • BPP = mechanism for modifying beans; @Transactional, @Async work through it
  • CGLIB (subclass) vs JDK Proxy (by interface)
  • @Transactional: rollback only for RuntimeException + Error by default
  • Self-invocation: calling a @Transactional method from the same class does NOT work
  • @Primary = default bean, @Qualifier = explicit choice
  • Profiles = different configuration for dev/test/prod

Senior

  • 3-level cache for circular dependencies: singletonObjects, earlySingletonObjects, singletonFactories
  • Full mode (@Configuration) = CGLIB proxy, intercepts @Bean calls -> singleton. Lite mode = no proxy, each call = new instance
  • AOP: Spring AOP (runtime proxy, methods only) vs AspectJ (compile/load-time weaving, any join point)
  • Autoconfiguration: conditional (@ConditionalOnClass, @ConditionalOnMissingBean), spring.factories -> .imports (Boot 2.7+)
  • @Autowired resolution: byType -> @Qualifier -> @Primary -> byName
  • proxyBeanMethods = false: faster startup, but @Bean inter-calls create new instances
  • Transaction propagation: REQUIRED (default), REQUIRES_NEW, NESTED, etc.

File Format

Each file contains:

  • Junior Level - basic understanding, simple analogies, examples
  • Middle Level - internals, common pitfalls, practical examples
  • Senior Level - deep dive, edge cases, production experience, monitoring
  • Interview Cheat Sheet - key points, common questions, red flags, related topics