I have a bean definition in Spring and it's proxy counterpart which is meant to be used everywhere:
<bean name="my.Bean" class="org.springframework.aop.framework.ProxyFactoryBean" scope="prototype">
<property name="proxyInterfaces" value="my.Interface"/>
<property name="target" ref="my.BeanTarget"/>
<property name="interceptorNames">
<list>
<value>someInterceptor</value>
</list>
</property>
</bean>
<bean name="my.BeanTarget" class="my.InterfaceImpl" scope="prototype">
<property name="foo" ref="bar"/>
</bean>
This all works well; and in pre-Spring v3 world I was using it like
ApplicationContext ctx = ...;
my.Interface foo = (my.Interface) ctx.getBean("my.Bean"); // cast is necessary
In Spring 3 it became possible to do type safe lookups, e.g.:
my.Interface foo = ctx.getBean(my.Interface.class);
Again, this works well for ordinary beans whereas for proxied beans I am getting my.BeanTarget
instead of my.Bean
. I have tried to inline my.BeanTarget
(as shown in Spring documentation) to make it hidden, but all I got was
org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [my.Interface] is defined: expected single bean but found 0:
So is it possible to use type safe bean lookups with proxied beans and if yes - how?