Align AOT contributions for injection with the runtime behavior

Bean post processors that use InjectionMetadata checks if a property
value for the element it is about to inject is set and skip it, so
that the property value is used. Previously, the AOT contribution for
the same behavior did not check if a matching property value is set
and therefore override the user-defined value.

This commit introduces an additional method that filters the injected
element list so that only the elements that should be processed are
defined.

Closes gh-30476
This commit is contained in:
Stephane Nicoll
2023-05-11 16:00:21 +02:00
parent a9b94241af
commit c3c5eaf914
5 changed files with 79 additions and 14 deletions

View File

@@ -359,7 +359,8 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
String beanName = registeredBean.getBeanName();
RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition();
InjectionMetadata metadata = findInjectionMetadata(beanDefinition, beanClass, beanName);
Collection<InjectedElement> injectedElements = metadata.getInjectedElements();
Collection<InjectedElement> injectedElements = metadata.getInjectedElements(
registeredBean.getMergedBeanDefinition().getPropertyValues());
if (!CollectionUtils.isEmpty(injectedElements)) {
return new AotContribution(beanClass, injectedElements);
}