Java and Spring Level 1 This level · 82 of 105
Easy java spring

Why does Spring Boot prefer convention over configuration?

The 30 second answer

Spring Boot provides sensible defaults because most applications need the same basic infrastructure, like a connection pool, JSON support and logging. Instead of configuring everything from scratch, I configure the parts that are different for my application. Conditions such as @ConditionalOnMissingBean let many defaults back off when I supply my own beans, and configuration properties let me tune the defaults without replacing them.

Could you say this in an interview?

Spring Boot's own docs describe its goals as giving a fast getting-started experience, being "opinionated out of the box but get out of the way quickly as requirements start to diverge from the defaults", and needing no code generation or XML.

How that works in practice:

1. Defaults come from auto-configuration. If HikariCP and a JDBC driver are on the classpath and you set spring.datasource.url, you get a pooled DataSource. If Jackson is present, you get a configured ObjectMapper. You do not write these beans.

2. Defaults back off. The defaults are guarded by conditions such as @ConditionalOnMissingBean. The docs call this "gradually replacing auto-configuration": if you add your own DataSource bean, the default one is no longer created.

3. Defaults are tunable without code. Most settings are bound from properties: server.port, spring.datasource.hikari.maximum-pool-size, logging.level.*. You change behaviour in application.yml or environment variables.

4. Dependencies are curated. The Spring Boot dependency BOM picks tested versions of libraries, so you rarely write a version number.

Why this matters:

  • Less boilerplate: a REST service with a database can start with one class and a few properties.
  • Consistency: teams share the same defaults, so services look alike and are easier to operate.
  • Escape hatches: you can override one bean, exclude one auto-configuration, or set one property without fighting the framework.

Trade-offs to mention:

  • "Magic": new developers may not know where a bean comes from. The answer is --debug (condition evaluation report) and the Actuator conditions and beans endpoints.
  • Unused starters add classes and work at startup.

Editor's note: in an interview, show you know the escape hatches: @ConditionalOnMissingBean back-off, exclude, and properties. That shows you see convention as a default, not a cage.

Sources (2)
  1. Spring Boot reference: Overview (goals)docs.spring.io
  2. Spring Boot reference: Gradually replacing auto-configurationdocs.spring.io
Previous
Next