How Spring Boot Auto Configuration Works with Spring's @EnableAutoConfiguration Annotations

preview_player
Показать описание
One of the most compelling features of Spring and Spring Boot is AutoConfiguration.

The Spring EnableAutoConfiguration annotation, and the various AutoConfig classes that support it, are what makes auto configuration in Spring Boot possible.

In this Spring Boot tutorial, autoconfiguration with the EnableAutoConfiguration annotation is explored.

We show you how Spring auto configuration works with and without Spring Boot. We show you how Spring allows autoconfigured resources to be autowired in as beans, and we show you how to achieve the same autoconfiguration results yourself.

We then explore all of the autoconfigurable types in Spring Boot, and then show you how to create a Spring Boot auto configuration class of your own.

If you want to be an expert at Spring Boot autoconfiguration and the Spring EnableAutoConfiguration annotation, this is the right Spring tutorial for you!

FROM THE SPRING JAVADOC:

When using @SpringBootApplication, the auto-configuration of the context is automatically enabled and adding this annotation has therefore no additional effect.

The package of the class that is annotated with @EnableAutoConfiguration, usually through @SpringBootApplication, has specific significance and is often used as a 'default'. For example, it will be used when scanning for @Entity classes. It is generally recommended that you place @EnableAutoConfiguration (if you're not using @SpringBootApplication) in a root package so that all sub-packages and classes can be searched.

Auto-configuration classes are regular Spring @Configuration beans. They are located using ImportCandidates. Generally auto-configuration beans are @Conditional beans (most often using @ConditionalOnClass and @ConditionalOnMissingBean annotations).
Рекомендации по теме
Комментарии
Автор

Thank you Cameron. I was wondering if we can use auto configuration for our library. Specifically, the library which has some beans and entity (we have the same table in each service and we want to handle it with library). The problem is with EntityScan. If you use it in library then spring disables it from autoconfig. That means each service would need to create it's own EntityScan to scan their entities which is really bad. I was wondering if you have any ideas how we can solve that. Thanks.

volodymyr
Автор

This is amazing, the only thing that could be improved is to use IDEA instead of Eclipse :)

nikitakarpenka
welcome to shbcf.ru