Skip to content

getBeanNamesForType(ResolvableType) does not reliably work for beans with AOP proxies [SPR-14097] #18669

Closed
@spring-projects-issues

Description

@spring-projects-issues

David J. M. Karlsen opened SPR-14097 and commented

Relates to #16761

When beans are instrumented with interceptors it doesn't resolve them properly.
E.g. this returns me 0 candidates:

ResolvableType resolvableType = ResolvableType.forClassWithGenerics( StgBusinessService.class, function.getClass() );

while this works

private <T extends Function> StgBusinessService<T> findBusinessService( T t ) {
        Map<String,StgBusinessService> services = applicationContext.getBeansOfType( StgBusinessService.class );
        ParameterizedType parameterizedType = TypeUtils.parameterize( StgBusinessService.class, function.getClass() );

        return services
            .values()
            .stream()
            .filter( service -> ArrayUtils.contains( AopUtils.getTargetClass( service ).getGenericInterfaces(), parameterizedType ) )
            .findFirst()
            .orElseThrow( () -> new IllegalStateException( "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.


Affects: 4.2.5

Issue Links:

Referenced from: commits f805427, 9a39a25, 3b7ca7e, edea66a

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions