@Bean Annotation : Java Configuration



In case if you are using @Bean annotation then you need to create and returned the bean 
as given in below example. This is called Java Configuration.
Each bean is having a ID which we provide with the name attribute in @Bean annotation. If you do not provide the name with the @Bean annotation then the name of the class will be taken as the bean name. you can specify bean name like : @Bean(name="hello")

@Configuration
public class DemoFlight {

public static void main(String[] args) {
 AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DemoFlight.class);
 try{
    System.out.println("One: " +ctx.getBean(One.class));
    System.out.println("Two: " +ctx.getBean(Two.class));
 }finally { 
 ctx.close();
 }
}

@Bean
public One getOne() {
return new One();
}

@Bean(name="two")
public One getTwo() {
return new Two();
}
}

package com.data.first;
public class One {}

package com.data.two;
public class Two {}

But when you use @Component on bean class and @ComponentScan
in configuration class you do not need to create and returned the bean spring will
automatically create the required bean as per dependency. That is called automatic configuration.