What is spring.datasource configuration?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid Spring Boot basics — a prerequisite for any developer role.
Answer
Spring Boot auto-configures a DataSource when a database driver and spring-boot-starter-data-jpa or spring-boot-starter-jdbc are on the classpath. Configuration properties: spring.datasource.url=jdbc:postgresql://localhost:5432/mydb spring.datasource.username=postgres spring.datasource.password=secret spring.datasource.driver-class-name=org.postgresql.Driver. Spring Boot auto-detects the driver from the URL in most cases. Connection pool (HikariCP — default): Spring Boot uses HikariCP by default (fastest connection pool for Java). spring.datasource.hikari.maximum-pool-size=10 spring.datasource.hikari.minimum-idle=5 spring.datasource.hikari.connection-timeout=30000 spring.datasource.hikari.idle-timeout=600000 spring.datasource.hikari.max-lifetime=1800000. Multiple datasources: define primary and secondary DataSource beans explicitly with @Primary and @Qualifier. JPA properties: spring.jpa.hibernate.ddl-auto=validate # or: create, create-drop, update, none spring.jpa.show-sql=true # Log SQL statements spring.jpa.properties.hibernate.format_sql=true spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect. ddl-auto values: none — do nothing; validate — validate schema matches entities (recommended for production); update — update schema (risky in production); create — drop and create; create-drop — create on start, drop on close (for testing). Flyway/Liquibase: use database migration tools instead of ddl-auto for production schema management.
Common Mistake
Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Spring Boot candidates.