Skip to content

Allow @Configuration classes to self-@ComponentScan [SPR-8808] #13450

Closed
@spring-projects-issues

Description

@spring-projects-issues

Tomasz Nurkiewicz opened SPR-8808 and commented

I am using AnnotationConfigWebApplicationContext and XML-free testing support with @ContextConfiguration(classes=...). When pointed @Configuration class contains @ComponentScan with a package containing that class:

package com.example.foo;

@Configuration
@ComponentScan(basePackages = "com.example.foo")
public class Config { }

I get unexpected exception:

org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'config' for bean class [com.example.foo.Config] conflicts with existing, non-compatible bean definition of same name and class [com.example.foo.Config]

While I understand why it happens, IMHO Spring should handle this case and simply ignore @Configuration found in scanned package if it has already been provided in AnnotationConfigWebApplicationContext.

Test case attached. On branch master you'll find a test case failing, branch fix fixes the problem by simply @Config to another package.


Affects: 3.1 RC1

Attachments:

Issue Links:

Referenced from: commits ca4eafd, 6991cd9

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions