-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
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:
- Allow recursive use of @ComponentScan [SPR-8307] #12956 Allow recursive use of
@ComponentScan("is superseded by")