Open source reader

Monday, April 24, 2006

A simple Spring bean retrieval convention

In his blog entry Ryan was talking about its switch to spring, and used such code for bean retrievals:
UserDAO dao = (UserDAO)DAOFactory.getDAO(DAOFactory.USER_DAO);

srini added a nice comment I am sharing with you

Typically, I just name the spring beans after the interface they represent for example...

<bean id="com.foo.BarRepository" class="com.foo.BarRepositoryJDO">
<constructor-arg><ref bean="javax.jdo.PersistenceManagerFactory" /></constructor-arg>
</bean>


So, when I have to look them up, I go...

beanFactory.getBean(BarRepository.class.getName());

Makes life easier while re-factoring as well. What conventions do you use ?
Like for log4j I do not like using such methods, I find the getName() not adding any value, Why not giving only the class ?

beanFactory.getBean(BarRepository.class);

Unfortunately it is not handled in the api...

0 Comments:

Post a Comment

<< Home