2V0-72.22PSE · Question #78
Refer to the exhibit. Which two statements are correct regarding auto-configuration of DataSource and JdbcTemplate beans given a Spring Boot application with only these two dependencies? (Choose two.)
The correct answer is C. A JdbcTemplate bean will be auto-configured. E. A DataSource bean will be auto-configured. When Spring Boot detects spring-boot-starter-jdbc (or spring-jdbc) on the classpath along with an embedded database driver like H2, HSQLDB, or Derby, it automatically wires up both a DataSource bean (pointing to the embedded DB) and a JdbcTemplate bean (using that DataSource)…
Question
Refer to the exhibit. Which two statements are correct regarding auto-configuration of DataSource and JdbcTemplate beans given a Spring Boot application with only these two dependencies? (Choose two.)
Exhibit
Options
- AA DataSource bean will not be auto-configured.
- BA JdbcTemplate bean will not be auto-configured.
- CA JdbcTemplate bean will be auto-configured.
- DA DataSource bean will be auto-configured only if a JdbcTemplate bean is explicitly defined.
- EA DataSource bean will be auto-configured.
How the community answered
(23 responses)- A4% (1)
- C91% (21)
- D4% (1)
Explanation
When Spring Boot detects spring-boot-starter-jdbc (or spring-jdbc) on the classpath along with an embedded database driver like H2, HSQLDB, or Derby, it automatically wires up both a DataSource bean (pointing to the embedded DB) and a JdbcTemplate bean (using that DataSource) - making C and E correct. No manual @Bean definitions are needed; Spring Boot's DataSourceAutoConfiguration and JdbcTemplateAutoConfiguration handle this entirely.
Why the distractors are wrong:
- A is the direct opposite of the truth - the embedded DB on the classpath is exactly what triggers
DataSourceauto-configuration. - B is wrong because
JdbcTemplateAutoConfigurationfires whenever aDataSourcebean is present (auto-configured or otherwise). - D inverts the actual dependency:
JdbcTemplatedepends onDataSource, not the other way around.DataSourceis configured independently and does not care whether aJdbcTemplateexists.
Memory tip: Think of it as a chain - embedded DB driver → DataSource → JdbcTemplate. If the first link is on the classpath, Spring Boot auto-builds the whole chain. You only need to break the chain yourself (with spring.datasource.* properties) if you want a non-embedded database.
Topics
Community Discussion
No community discussion yet for this question.
