- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Description
Johannes Zick opened SPR-13118 and commented
In our project, we use a custom Scope that can be controlled to some degree by the application. The Bean is declared in a @Configuration class using the @Bean annotation. The same class contains the CustomScopeConfigurer declaration referencing the Scope by method name.
@Configuration
public class Configuration
{
    @Bean
    static CustomScope getCustomScope()
    {
        return new CustomScope();
    }
    @Bean
    static CustomScopeConfigurer getCustomScopeConfigurer()
    {
        CustomScopeConfigurer customScopeConfigurer = new CustomScopeConfigurer();
        customScopeConfigurer.addScope("customScope", getCustomScope());
        return customScopeConfigurer;
    }
}
To control the custom Scope, we tried to inject it using @Autowired. This resulted in a new Bean being created. To access the Bean being used internally, we have to inject the ApplicationContext, retrieve the BeanFactory, then the registered Scope.
Usually, one would expect to have easy access to the custom Scope, since it is declared in the same @Configuration class. But apparently it lives in a completely separate Context. I can access it, however, via public methods.
I would highly recommend to change this, and add a word or two to the Javadocs. Either have it in a separate Context and not accessible, or allow access and make it injectable. The current behavior is inconsistent and not documented, as far as I can tell.
Affects: 4.1.5
Issue Links:
- Doc: Autowiring in @Configuration classes with post-processor definitions [SPR-13285] #17875 Doc: Autowiring in @Configurationclasses with post-processor definitions
Referenced from: commits f58e1db