I came across two annotations provided by Spring 3 (@Component and @Configuration)
I am a bit confused between these.
Here is what I read about @Component
Although this is old, but elaborating on JavaBoy And Vijay's answers, with an example:
@Configuration
public class JavaConfig {
@Bean
public A getA() {
return new A();
}
}
@Component
@ComponentScan(basePackages="spring.example")
public class Main() {
@Bean
public B getB() {
return new B();
}
@Autowired
JavaConfig config;
public static void main(String[]a) {
Main m = new AnnotationConfigApplicationContext(Main.class)
.getBean(Main.class);
/* Different bean returned everytime on calling Main.getB() */
System.out.println(m.getB());
System.out.println(m.getB());
/* Same bean returned everytime on calling JavaConfig.getA() */
System.out.println(m.config.getA());
System.out.println(m.config.getA());
}
}