-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Revisit @Bean introspection between @Configuration classes and 'lite' beans [SPR-17206] #21739
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
Comments
Stéphane Nicoll commented I like this idea, we could configure this automatically in the next feature release of Spring Boot before eventually deprecating/removing the feature. |
Juergen Hoeller commented The original motivation was not the cost of CGLIB subclass generation but rather the limitations that come with it: e.g. no That said, simple |
Juergen Hoeller commented FWIW, we also got #21674 as a recent case for where a pointlessly created CGLIB proxy turned out as a showstopper, in this case with Kotlin. |
Sam Brannen commented Juergen Hoeller, if you do any work on this issue, please keep in mind that this topic is related to #21136. |
Dave Syer commented Maybe we could have an explicit option to only load beans from spring.components, and extend that index to include lite beans for people that need them (or are using them inadvertently)? Cutting out the recursive search through all bean classes and nested classes is the main outcome I was seeking TBH. |
Juergen Hoeller commented I've restricted the nested class search to For the above-mentioned two issues, this is a worthwhile revision in its own right. Beyond that, whether it covers a lot of ground in terms of startup performance is rather doubtful: The startup overhead for nested classes only really shows for top-level classes with configuration indicators since otherwise we wouldn't search the nested classes to begin with. As for searching top-level classes themselves for |
Dave Syer commented It covers some ground in terms of startup performance. A micro app with no The decision about |
Juergen Hoeller commented
As for a more extensive annotation index, this is indeed worth pursuing. Our current components indexer is rather simple, after all, and certainly has the potential to become more sophisticated (towards an indication for annotated methods in particular). |
Dave Syer opened SPR-17206 and commented
There is a lot of evidence that
ConfigurationClassPostProcessor
is bad for startup time. There is also some evidence that part of the problem is lite bean configuration - we have to scan all methods of all bean definition classes looking for@Bean
. To investigate this I made a version ofConfigurationClassPostProcessor
that only uses classes fromspring.components
. It is much faster when there are no@Configuration
classes.The rationale for introducing lite beans was IIRC so that you wouldn't pay the cost of CGLib proxying. But that is so much faster now than it was when we invented
@Configuration
I don't believe it adds up any more - the cost of processing annotations is much higher. And we have to recursively search all nested classes of all bean definitions. Ugh.If lite beans were optional, Spring Boot could switch them off, and we can flush out all the usages (which are probably mostly accidental at this point).
Affects: 5.0.8
Issue Links:
@Nested
class cannot share enclosing class's ApplicationContext if nested class is deemed to be a configuration candidate@EventListener
@Component
instances as@Configuration
candidates@Configuration
classes@Import
classes as lite@Configuration
@ComponentScan
should get processed without@Configuration
as well2 votes, 8 watchers
The text was updated successfully, but these errors were encountered: