๐๐ SPRING CERTIFICATION QUESTION: How does Spring Boot work? How does it know what to configure?
๐๐ SPRING CERTIFICATION QUESTION: How does Spring Boot work? How does it know what to configure?
๐ฉโ๐ซ Answer:
Autoconfiguration โ๏ธ facility is provided by ๐ ๐๐๐๐๐-๐๐๐๐ก-๐๐ข๐ก๐๐๐๐๐๐๐๐ข๐๐ jar.
This jar lists autoconfiguration classes under ๐๐๐๐-๐๐๐ /๐ฌ๐ฉ๐ซ๐ข๐ง๐ .๐๐๐๐ญ๐จ๐ซ๐ข๐๐ฌ file, the presence of which is checked โ by Spring Boot.
It's important to emphasize that autoconfiguration classes should be registered ๐พ this way only, and should never be the target ๐ฏ of component scanning.
Usually, autoconfiguration classes are annotated with ๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ annotation which specifies a condition that should match ๐ค in order for a component to be registered.
Those conditional annotations can be divided ๐ช into the following groups:
- 1. Class conditions (๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐ฅ๐๐ฌ๐ฌ, ๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐ข๐ฌ๐ฌ๐ข๐ง๐ ๐๐ฅ๐๐ฌ๐ฌ}) - which check the presence or absence of a class on the classpath.
- 2. Bean conditions (๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐๐๐ง, ๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐ข๐ฌ๐ฌ๐ข๐ง๐ ๐๐๐๐ง) - which check the presence or absence of a bean in the ๐๐๐๐ง๐ ๐๐๐ญ๐จ๐ซ๐ฒ.
- 3. Property conditions (๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐ซ๐จ๐ฉ๐๐ซ๐ญ๐ฒ) - which check presence or absence of Spring ๐๐ง๐ฏ๐ข๐ซ๐จ๐ง๐ฆ๐๐ง๐ญ property.
- 4. Resource conditions (๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐๐ฌ๐จ๐ฎ๐ซ๐๐) - which check the presence or absence of a resource.
- 5. Application context type conditions (๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐๐๐๐ฉ๐ฉ๐ฅ๐ข๐๐๐ญ๐ข๐จ๐ง, ๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐จ๐ญ๐๐๐๐๐ฉ๐ฉ๐ฅ๐ข๐๐๐ญ๐ข๐จ๐ง) - which check the configured type of ๐๐ฉ๐ฉ๐ฅ๐ข๐๐๐ญ๐ข๐จ๐ง๐๐จ๐ง๐ญ๐๐ฑ๐ญ.
- 6. SpEL conditions (๐๐จ๐ง๐๐ข๐ญ๐ข๐จ๐ง๐๐ฅ๐๐ง๐๐ฑ๐ฉ๐ซ๐๐ฌ๐ฌ๐ข๐จ๐ง) - which check a result of specific SpEL expression.
#spring #certificationquestion #vcp
Spring Conditional Annotations ๐ https://www.baeldung.com/spring-conditional-annotations