I seems have problem understanding these 2 annotation. I have try to read the javadocs but still cannot figure out. Can anyone help to explain with simple code about these 2 ? Thank so much in advance.
You use @Configuration
as a replacement to the XML based configuration for configuring spring beans. So instead of an xml file we write a class and annotate that with @Configuration
and define the beans in it using @Bean
annotation on the methods.
And finally you use AnnotationConfigApplicationContext
to register this @Configuration
class and thus spring manages the beans defined. Small example you can find at Spring Configuration Documentaion.
Quoting from the above link
It is just another way of configuration Indicates that a class declares one or more @Bean methods and may be processed by the Spring container to generate bean definitions and service requests for those beans at runtime.
And @Configurable
is an annotation that injects dependencies into objects that are not managed by Spring using aspectj libraries. i.e., you still use old way of instantiation with plain new
operator to create objects but the spring will take care of injecting the dependencies into that object automatically for you.