What is difference between these 2 Spring Annotation and XML config
1) Annotation Based
@Configuration
@EnableWebMvc
public class MyWebConfig{
//
}
2) XML Based
<mvc:annotation-driven />
I can not see any other difference than xml and annotation.
and When to use which one ?
@Treydone wrote some examples plus expressed subjective opinion about Java based config being better.
I disagree with this statement, because there is no functional difference between Java based configuration and XML configuration, it’s only matter of habit which one will you use. Some say traditional XML namespace config is better, others say Java based configuration (which is in Spring since 3.0) is the next level of IoC in Spring.
BTW Annotation based configuration is not the same as Java based one – you wrote example from the latter, so I assume you are choosing between XML and Java configs.
I think you should read:
and then decide which one is the best for you.
P.S. Annotation based configuration is IMO worse choice than these two as it moves some depedency information directly into ordinary classes.