@ComponentScan example



package com.data.first;
import org.springframework.stereotype.Component; 
@Component
public class BeanFirst { }

package com.data.second;
import org.springframework.stereotype.Component; 
@Component
public class BeanSecond { }

@Configuration
@ComponentScan(basePackages={"com.data.first","com.data.second"})
class AppConfig{
public static void main(String[] bag){

AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
try{
ctx.register(AppConfig.class);
        ctx.refresh();
          System.out.println("AppConfig: " +ctx.getBean(AppConfig.class));
        System.out.println("BeanFirst: " +ctx.getBean("BeanFirst.class));
          System.out.println("BeanSecond: " +ctx.getBean("BeanSecond.class));            
} finally { 
ctx.close();
         }
      }
}