difference between @Component and @Configuration in Spring 3

Viewed 34146

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

Put this “context:component” in the bean configuration file, it means, enable the auto-scanning feature in Spring. The base-package is indicate where are your components stored, Spring will scan this folder and find out the bean (annotated with @Component) and register it in Spring container.

So I am wondering what is the use of @Configuration then if @Controller will register my beans without the need to declare them in the spring configuration XML file.

5 Answers

@Component is a generic stereotype annotation which can indicate any of the candidate components i.e; @Repository, @Service, @Controller and these candidates are eligible for auto-detection.

Where as @Configuration is used to create component which is used by spring framework to create the application context, internally @Configuration makes use of @Component it makes sense reason being even that's a spring component which the framework itself creates.

Related