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
Add generics / parameterized type support to ListableBeanFactory getBeanNamesForType/getBeansOfType methods [SPR-12147] #16761
Comments
Lari Hotari commented This issue is related to #14599 . |
Lari Hotari commented I'm not actually sure if ResolvableType currently support the use case I'm looking to support. I'm working on a pull request for adding Spring Boot support to Ratpack , (exact location. Ratpack uses Guava's com.google.common.reflect.TypeToken (source) for holding generics type information. |
Phil Webb commented I think you can use TypeToken<List<String>> typeToken = new TypeToken<List<String>>() {};
ResolvableType resolvableType = ResolvableType.forType(typeToken.getType());
System.out.println(resolvableType);
System.out.println(resolvableType.getRawClass());
System.out.println(resolvableType.resolveGeneric(0)); Will output:
|
Rob Winch commented Perhaps I'm missing something. Is there a reason we need to add additional methods that accept a ResolvableType? Can you just look up the beans with the following? String[] beanNamesForType = context.getBeanNamesForType(resolvableType.resolve());
Map<String, ?> beansOfType = context.getBeansOfType(resolvableType.resolve());
Map<String, ?> beansOfTypeRefined = context.getBeansOfType(resolvableType.resolve(), includeNonSingletons, allowEagerInit); For others looking at this issue, you don't even need Guava to resolve the generic type. You can use something like: ResolvableType resolvableType = ResolvableType.forClassWithGenerics(List.class, String.class); |
Juergen Hoeller commented As far as I understand this issue, the intent is to pass the full generic type information to the bean factory there, analogous to introspecting a method parameter declaration. A Juergen |
Juergen Hoeller commented I'm looking into this at the moment... From my perspective, a And with respect to the Juergen |
Juergen Hoeller commented I've introduced I'm rather opposed to further convenience variants. I'd only add further variants for retrieval attempts that cannot be expressed any other way. Juergen |
Lari Hotari opened SPR-12147 and commented
Spring currently doesn't have a public API for finding beans based on generics type information. Generic types seem to only be supported in autowiring fields or methods (Spring blog article).
There is a discussion about this feature in the issue comments of SPR-9965 .
I'd like to have generics support in ListableBeanFactory:
Affects: 4.0.6, 4.1 RC2
Issue Links:
Referenced from: commits b230892, 778a019
0 votes, 11 watchers
The text was updated successfully, but these errors were encountered: