Back Forum Reply New

BeanNameAware confusion

Why does BeanNameAware return a bean name that when looked up via appContext.getBean(beanName) is unknown.

The setBeanName() injects a bean name similar to quot;com.foo.bar.MyClassName#1df5f21quot;

While the getBean() expects a name corresponding to the id given to the bean in configuration similar to quot;myClassNamequot;

Rather confused, can someone point me in the right direction. Thanks.

Could it be that the bean in question is an inner bean (i.e. part of a property definition)?

In that case you do not have to provide a name, but Spring generates one for internal purposes. By design, inner beans cannot be retrieved from the context. If such a bean implements BeanNameAware it would cause the scenario you describe.

Generally, what you tried should work, but not with inner beans.

Regards,
Andreas

Thanks Andreas,

It was an inner-bean, wrapped in a transaction proxy.
¥
Back Forum Reply New