Here is the difference between annotation based vs java based configuration, may be it will help you to find the answer.
1.Xml based configuration :
a) In xml based configuration you can define you bean definition/dependency-injections/auto-wiring inside a xml file.
b)If you want to give only the bean definitions inside your XML file and for rest, you want to use annotations then you have to define context:annotation-config
in your XML file.
c)If you want to use only annotations for all the things then you have to define context:component-scan
in your XML file.
2.Java based configuration: If you want to use a java based configuration then you have to use @Configuration
annotation over your class which you will use to load the container.Now for the bean definition, you can do with in two.
a)In your configuration class @Bean
annotations over the factory methods which you give you your bean objects by using the new keyword.
example-
@Bean
public HelloWorld helloWorld(){
return new HelloWorld();
}
b) @Component
/@Service
/@Repository
/@Controller
/@RestController
over the class which you want to act as a bean.