What is the use case of @Import annotation?

If component scanning is enabled, you can split bean definitions in multi @Configuration classes without using @Import. And you don’t need to provide all of them to the application context constructor.

I think the main purpose for @Import is to provide you a way to simplify multiple configurations registration if you’d like to avoid component scanning (as of Spring Framework 4.2, per reference manual).

There’s a note in Spring Reference Documentation about @Import usage:

As of Spring Framework 4.2, @Import also supports references to regular component classes, analogous to the AnnotationConfigApplicationContext.register method. This is particularly useful if you’d like to avoid component scanning, using a few configuration classes as entry points for explicitly defining all your components.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)