@ComponentScan scans and searches for any beans inside packages/classes specified under basePackageClasses or basePackages options, whichever is configured.
This option also allows you to filter some classes that you do not want to be included in search.
@Import is like clubbing one java configuration into another.
eg:
@Configuration
@ComponentScan(basePackages="com.stackoverflow")
public class Dbconfig {
@Bean
public Datasource dSource(){
return new Datasource()
}
}
@Configuration
@Import(Dbconfig.class)
@ComponentScan(basePackages="org.hellospring")
public class AppConfig {
...// beans
}
So here, if we check AppConfig class,
it will include all beans registered in Dbconfig configuration class including inside of package com.stackoverflow
+
It will include all beans inside AppConfig class and beans under package org.hellospring