1. @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)
  2. #2
    alexbarnes is offlineMember
    Join Date
    Jun 2011
    Posts
    31

    Default

    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





Posted by linuxism
,