You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getBeanNamesForType(ResolvableType) does not reliably work for beans with AOP proxies [SPR-14097] #18669
private <TextendsFunction> StgBusinessService<T> findBusinessService( Tt ) {
Map<String,StgBusinessService> services = applicationContext.getBeansOfType( StgBusinessService.class );
ParameterizedTypeparameterizedType = TypeUtils.parameterize( StgBusinessService.class, function.getClass() );
returnservices
.values()
.stream()
.filter( service -> ArrayUtils.contains( AopUtils.getTargetClass( service ).getGenericInterfaces(), parameterizedType ) )
.findFirst()
.orElseThrow( () -> newIllegalStateException( "No handler for function type: " + function ) );
}
The 1st variant passes in my simple unit-test where there are no application of AOP, while it doesn't when loading the full-blown application which adds AOP.
The recent fix for #19578 addressed the problem for type prediction against factory methods, also behind proxies. Type prediction also works for AOP proxies now, but for already instantiated singleton objects, only CGLIB proxies are correctly matched in terms of generics.
For interface-based JDK proxies, we need to explicitly look at the target type of the bean if the proxy type doesn't generically match. At the BeanFactory level, we typically do that through checking resolved types on the underlying bean definition, which also does the job here. This is largely equivalent to an AOP target class check but does not require Spring AOP specifics and therefore no spring-aop dependency; as a bonus, it also works with custom JDK proxies.
Activity
spring-projects-issues commentedon Dec 25, 2016
Juergen Hoeller commented
The recent fix for #19578 addressed the problem for type prediction against factory methods, also behind proxies. Type prediction also works for AOP proxies now, but for already instantiated singleton objects, only CGLIB proxies are correctly matched in terms of generics.
For interface-based JDK proxies, we need to explicitly look at the target type of the bean if the proxy type doesn't generically match. At the BeanFactory level, we typically do that through checking resolved types on the underlying bean definition, which also does the job here. This is largely equivalent to an AOP target class check but does not require Spring AOP specifics and therefore no spring-aop dependency; as a bonus, it also works with custom JDK proxies.