-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Provide functionality similar to Spring Boot's BeanTypeRegistry #23341
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
Conversation
Update `ListableBeanFactory` and `BeanFactoryUtils` to add the missing `getBeanNamesForType` methods that accept a `ResolvableType` rather than a `Class`. This completes the work started in 778a019. Closes spring-projectsgh-23335
Update the logic in `AbstractBeanFactory` so that caches from merged bean definitions remain whenever possible. Prior to this commit, all merged bean definitions would be completely removed after bean post processing in case a processor changed the bean type. It's fairly unlikely these days that the bean type will actually change, so instead we now compare a subset of the old cached properties against the newly created definition. Only if key properties have changed do we now discard the older cached values. Closes spring-projectsgh-23336
Add an additional cache to the `RootBeanDefinition` to save recalculating the result of `isFactoryBean`. Closes spring-projectsgh-23337
Update the `FactoryBean` type prediction logic (primarily in the `DefaultListableBeanFactory`) so that generic type information is considered when calling `getBeanNamesForType` on a non-frozen configuration. Calling `getBeanNamesForType` with `allowEagerInit` disabled will now detect `FactoryBean` variants as long as generic type information is available in either the class or the factory method return type. Closes spring-projectsgh-23338
Update `getTypeForFactoryBean` detection so that a bean definition attribute can be used to supply the result. This commit allows projects such as Spring Data to provide the result that would be supplied by `getObjectType` early so that we don't need to initialize the `FactoryBean` unnecessarily. Closes spring-projectsgh-23338
Update code that's often called so that zero length array results use a single shared static constant, rather than a new instance for each call. Closes spring-projectsgh-23340
@philwebb Your changes look good. In context to spring-projects/spring-boot#16615, I have one (probably silly) question: Is there a way to ask the BeanFactory for a Bean Definition's type without forcing the initialization of that bean? Essentially a I am likely missing something obvious. I could change the Predicate to accept a |
@tkvangorder I'm not sure there is such an API yet. I've raised #23374 to look into it after this one is merged. |
Initial attempt at fixing the issues raised from #23056. Since these changes are quite core, careful review is required.