Skip to content

Support beanFactory.getBean(Bar.class) signature to instantiate a bean. [SPR-1956] #6649

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

1 votes, 1 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions