Card 05/ 06
All 6 cards
ExerciseDifficulty: Advanced1 min
Will Boot Create It?
Three scenarios. For each, say whether Spring Boot's auto-configuration creates a bean, and why.
spring-boot-starter-data-jpais on the classpath, and you've defined your ownEntityManagerFactorybean.spring-boot-starter-cacheis on the classpath, and you've added@EnableCachingyourself, with no cache-provider library present.- Nothing web-related is on the classpath at all, and your main class is annotated
@SpringBootApplication.
See the answers
- No.
@ConditionalOnMissingBeansees yourEntityManagerFactoryand backs off, the same as theDataSourcegotcha. - Yes, but a simple one. With no real provider on the classpath, Boot's own fallback — a basic
ConcurrentHashMap-backed cache — is what gets created.@ConditionalOnClassfor something like Caffeine fails, but caching itself was still asked for. - No embedded server, no
DispatcherServlet.@ConditionalOnClasschecks for Spring MVC and an embedded server implementation; neither is on the classpath, so that whole family of auto-configuration classes never activates.