Description
David Medinets opened SPR-1956 and commented
Given a bean definition like this:
<bean id="com.foo.BarRepository" class="com.foo.BarRepositoryJDO">
<constructor-arg><ref bean="javax.jdo.PersistenceManagerFactory" /></constructor-arg>
</bean>
If the beanFactory.getBean(Bar.class) signature were supported (ie, added to the BeanFactory interface), it would be possible to do:
BarRepository barRepository = (BarRepository)beanFactory.getBean(BarRepository.class);
This syntax is better than getBean("barRepository") because the Java compiler verifies the class name is spelled correctly. While advanced IDEs (ie, Eclipse) support does handle class name verification, not all people will be using such an IDE.
It may or may not be a good idea to require the Class to actually be an interface to ensure that 'best practices' are followed.
Issue Links:
- Support BeanFactory#getBean(Class<T> requiredType) [SPR-5529] #10200 Support BeanFactory#getBean(Class requiredType) ("duplicates")
1 votes, 1 watchers