What does Spring Boot auto-configuration do?
Options
- It rewrites your code automatically while compiling
- It reads the classpath and registers default beans (Correct option)
- It downloads any missing libraries while running
- It formats your code to match the Spring style
Answer
It inspects the classpath and your properties and registers sensible beans automatically (e.g. a DataSource if a JDBC driver is present), backing off if you define your own
Why
Auto-configuration classes are conditional: "if class X is on the classpath and no bean of type Y exists, create Y".
Example: add spring-boot-starter-data-jpa and a PostgreSQL driver, set the URL in properties, and Spring Boot creates the DataSource, EntityManagerFactory and transaction manager for you.
If you define your own bean of that type, the auto-configured one backs off. To see what happened, run with --debug.
Remember
Auto-config = conditional defaults that back off when you provide your own.