New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Scope and other common bean annotations on nested @Component classes [SPR-12486] #17092
Comments
Dave Syer commented N.B. I have some doubts whether |
Juergen Hoeller commented FWIW, a custom scope on a configuration class does work: It just means that for every invocation of a factory method on it, an instance of the configuration class is going to get obtained through that scope. Works quite naturally, even if it feels a little bit unusual. Note that beans defined by such a scoped configuration class will still be managed according to their own scope definition: a singleton bean defined by that configuration class will still be a singleton instance itself; it just happens to be created through the scoped config class. Juergen |
Dave Syer commented That's interesting because the problem reported above was easy to reproduce and the stack trace is quite intimidating. Does your assertion about custom scopes necessarily always hold? What if it's a scoped-proxy? (Maybe we are doing something wrong in Spring Cloud.) |
Juergen Hoeller commented Hmm, I've added several unit tests for scoped configuration classes, and they all pass as expected... That said, good point about scoped proxies. I'll dig into that next. Juergen |
Juergen Hoeller commented Scoped proxies turn out to work fine for configuration classes as well - for regular setup scenarios at least. I suspect the Spring Cloud issue above relates to #17050 due to some early initialization arrangements... Juergen |
Juergen Hoeller commented Common annotation processing for imported and nested classes within configuration classes is in master now. Please give the upcoming 4.1.3 snapshot a try, Dave... We're going to release 4.1.3 in time for Boot 1.2 GA still. Juergen |
Dave Syer commented I tried the latest snapshots and nearly everything works, but I still have 2 failing tests in Spring Cloud: https://github.com/spring-cloud/spring-cloud-config/blob/0d2cb07384/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeConfigurationTests.java#L67 and https://github.com/spring-cloud/spring-cloud-config/blob/0d2cb07384/spring-cloud-config-client/src/test/java/org/springframework/cloud/context/scope/refresh/ImportRefreshScopeIntegrationTests.java#L35). Any idea why they would not have scope="refresh"? |
Juergen Hoeller commented Hmm, both of those seem to be top-level configuration classes... It's unusual to have a scope on those, of course, but it should nevertheless work. Anything obvious showing up when looking at the bean definition state in the debugger? Juergen |
Dave Syer commented The Update: Actually that is expected. Still digging. |
Dave Syer commented All working as expected now (once I got my expectations aligned with reality). Thanks. |
Dave Syer opened SPR-12486 and commented
A nested static class inside
@Configuration
is considered for inclusion in the bean factory, and if it is a@Component
you get a bean definition, but the@Scope
on the class is ignored. A bean that is created by a component scan does not behave this way (I presume), neither does it when added explicitly to the bean factory (e.g. in the constructor of AnnotationConfigApplicationContext).I think #16497 refers obliquely to this problem. #13365 also looks relevant.
Affects: 4.1.2
Reference URL: spring-attic/spring-framework-issues#88
Issue Links:
@Configuration
should respect@DependsOn
on imported or nested classes as wellReferenced from: commits c5c5473
The text was updated successfully, but these errors were encountered: