Questions:
1) Difference between @Component and @Configuration?
I have read that both remove the necessity of
In most the answers above, users suggest to say that @Component and @ Configuration serve different purposes. But I do not see it happening in reality.
But I have a simple Spring MVC application.
@Configuration
public class SpringConfiguration {
@Bean
public InternalResourceViewResolver initViewResolver(){
InternalResourceViewResolver x = new InternalResourceViewResolver();
x.setPrefix("/WEB-INF/jsp/");
x.setSuffix(".jsp");
return x;
}
}
This main class works fine even if it is annotated as @Component instead of @Configuration.
Similarly inside a class annotated as @Component if you have methods annotated with @Bean, those beans are created when context is loaed.
So I think, it is just for code readability that we should mark main configuration class as @Configuration and other classes with @Component. Actual execution wise there seems no difference.