Sobes.tech
Middle

Have you written custom Spring Boot Starters or auto-configuration? What is the difference between Starter and auto-configuration?

sobes.tech AI

Answer from AI

Spring Boot Starter is a set of dependencies (usually in the form of a Maven/Gradle artifact) that simplifies the integration of functionality into a project. Starters gather the necessary libraries and configurations for a specific task (for example, spring-boot-starter-web).

Auto-configuration is a mechanism for automatically configuring the Spring context based on the presence of certain classes, properties, and conditions. Auto-configuration is implemented as classes annotated with @Configuration and conditional annotations (@ConditionalOnClass, @ConditionalOnProperty, etc.).

Difference:

  • Starters are a way to assemble dependencies and enable auto-configuration.
  • Auto-configuration is code that automatically sets up beans and parameters when the application starts.

When creating a custom starter, you typically create:

  • A Maven/Gradle module with dependencies.
  • An auto-configuration class that sets up beans.
  • A spring.factories file that registers the auto-configuration.

Thus, a starter is a package, and auto-configuration is the configuration logic.

Have you written custom Spring Boot Starters or… - sobes.tech