Skip to content

@Configuration classes are not enhanced with @ComponentScan [SPR-8069] #12724

Closed

Description

@spring-projects-issues

Magnus Kvalheim opened SPR-8069 and commented

I've tried to make use of spring's new features in 3.1 - namely @Profile and @ComponentScan

I have several profiles: test, dev and prod. (These creates embedded,basic or jndi datasources).

By using ComponentScan the classes annotated with @Configuration are not enhanced by cglib - so the @bean annotated methods are 'ignored' and not managed by container.

However - if I instead use @Import and explicitly specify the configuration classes - then they are properly enhanced.

Looking at documentation , 3.10.4 Defining bean metadata within components
"The @Bean methods in a Spring component are processed differently than their counterparts inside a Spring @Configuration class. The difference is that @Component classes are not enhanced with CGLIB to intercept the invocation of methods and fields. CGLIB proxying is the means by which invoking methods or fields within @Configuration classes @Bean methods create bean metadata references to collaborating objects. Methods are not invoked with normal Java semantics. In contrast, calling a method or field within a @Component classes @Bean method has standard Java semantics."

I would expect @Configuration classes to be enhanced when scanned as they are when they are imported.


Affects: 3.1 M1

Issue Links:

Activity

  1. spring-projects-issues commented on Mar 23, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    This indeed sounds like a bug. Thanks for the report, and we'll work it out by M2.

  2. spring-projects-issues commented on May 8, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Chris Beams commented

    The behavior described here is a side-effect of #12956. Please follow that issue to be notified of resolution.

  3. added
    type: bug
    status: duplicate
    and removed
    type: bug
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions