Configuration or AutoConfiguration?

Configuration or AutoConfiguration?

In this tutorial, learn to understand the difference between Configurations and AutoConfigurations in Spring boot!

Spring boot is all about magic. You add dependencies to the classpath and stuff just fits together and works. It provides a canvas for you to build on. The out-of-the-box configurations are opinionated and will make default configuration choices, at the same time these opinions and the configurations will be the first ones to get out of your way if you want to make your own configuration choices.

A lot of this magic because of AutoConfigurations. AutoConfiguration classes are very very similar to regular Configuration classes except for the following two differences:

  • AutoConfiguration classes are run last (meaning after all regular non-autoconfiguration classes) while the order in which Configuration classes are run is indeterminate (except if we use ordering annotations like @Ordered)
  • To declare a class as an AutoConfiguration they need to be specified as such in the spring.factories file. An example can be found here.

By now I am sure you are wondering when should one choose an AutoConfiguration class vs a Configuration class. Great question! Personally, I like to use an AutoConfiguration when:

  • The creation of beans depends on the presence of other beans. In other words, if you are considering using the @ConditionalOnBean or the @ConditionalOnMissingBean annotations.
  • Your configuration depends on other AutoConfigurations. You can use the @AutoConfigureAfter or @AutoConfigureBefore annotations to control the order of beans creation when it comes to AutoConfiguration classes.

Let's look at some examples!

kotlin

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Dedicated Kotlin Developer - WebClues Infotech

Request a free quote for custom web and mobile apps development, Enterprise solutions, IoT Solutions, AR/VR Development, Blockchain and chatbot services. Feel free to get in touch.

How to Develop an Android App with Kotlin?

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

Top Kotlin Android App Development Company in USA

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

Top-notch Kotlin App Development Company in USA

AppClues Infotech is a top Mobile App Development Company in USA building high-quality Android, iOS, and Native apps for Startups, SMBs, & Enterprises. Contact us now!

Kotlin or React Native | React Native vs Kotlin Performance Comparison

This blog provides quick analysis to decide whether to opt for Kotlin or React Native to build robust and secure mobile application.