I have the name of a bean of unknown scope. I'm trying to determine its static type (the class annotated with @Component
, or the return type of the @Bean
factory method) in a reliable way (that deals with proxies etc).
BeanFactory.getType(beanName)
gives me a proxy class.BeanFactory.getBeanDefinition(beanName).getResolvableType()
in many cases gives me anEmptyType
.
All utility methods for determining the bean type, like AopUtils.getTargetClass()
and AopProxyUtils.ultimateTargetClass()
require an actual instance, which I can not safely obtain for non-singletons.
If the bean is created by a factory method, I can find the method via beanDefinition.getSource()
and get its return type from there. But nothing seems possible for @Component
annotated classes. I can get the class name, but not the class itself (and loading it by name is a can of worms I'd rather avoid).
Is there anything I can do here?