Spring 3 introduced the @Configuration, @Bean, @import, and @DependsOn annotations to configure and define Spring beans using Java.
You have already learned about the @Configuration and @Bean annotation in the Defining beans section. Now, you will explore how to use the @import and @DependsOn annotations.
The @Import annotation is more useful when you develop an application without using autoconfiguration.
The @Import annotation
This is used for modularizing configurations when you have more than one configuration class. You can import the bean's definitions from other configuration classes. It is useful when you instantiate the context manually. Spring Boot uses autoconfiguration, therefore you don't need to use @Import. However, if you want to instantiate the context manually, then you would have to use @Import to modularize the configurations.
Let's say the configuration class FooConfig contains FooBean and the configuration class BarConfig contains BarBean. The BarConfig class also imports FooConfig using @Import: