@Configuration conflict with @ComponentScan
I have one @Configuration annotated class with a @ComponentScan on my complete project.
When I register this class to the AnnotationConfigApplicationContext, I get an error message: org.springframework.context.annotation.Conflicting BeanDefinitionException: Annotation-specified bean name 'applicationConfig' for bean class [nl.project.config.ApplicationConfig] conflicts with existing, non-compatible bean definition of same name and class [nl.project.config.ApplicationConfig].
Probably because @Configuration is annotated with @Component, this bean is added twice.
This doesn't seem right to me.
(tested in the latest nightly build)
Jun 22nd, 2011, 11:21 AM#2 I have found this and the answer is that your component scan is picking up your @Configuration bean.
The way to avoid this is to use an exclude filter on your component scan annotation.
Code:
@ComponentScan(
basePackages = {"nl.project.config"},
excludeFilters = {
@Filter(value = ApplicationConfig.class, type = FilterType.ASSIGNABLE_TYPE)})
출처 - http://forum.springsource.org/showthread.php?111056-Configuration-conflict-with-ComponentScan