In case you missed it on TSS or Chris Richardson's blog...Once a Spring application gets large enough, you'll probably find that there are several beans configured in your Spring application context that are pretty much the same. For example:
<bean id="customerDao" class="com.habuma.dao.CustomerDaoImpl"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="productDao" class="com.habuma.dao.ProductDaoImpl"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="orderDao" class="com.habuma.dao.OrderDaoImpl"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="vendorDao" class="com.habuma.dao.VendorDaoImpl"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="categoryDao" class="com.habuma.dao.CategoryDaoImpl"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="specialDao" class="com.habuma.dao.SpecialDaoImpl"> <property name="dataSource" ref="dataSource" /> </bean>
Notice a pattern?
This was just a contrived example, but you've probably seen something very similar (or worse) in your Spring application. Sure, you could use auto-wiring to cut down on the XML, but that would only help out a little bit. You'd still have to declare each bean. If only there were some way to not only auto-wire, but to also auto-declare...
Enter Arid POJOs, a Spring configuration extension by Chris Richardson (the author of POJOs in Action) that lends to DRY bean configuration. Using Arid POJOs, you can dramatically cut down on the amount of XML in your Spring configuration file by declaring rules for auto-declaring beans. For example, the DAO beans above can be more succinctly declared with the following XML:
<arid:define-beans package="com.habuma.dao" autowire="byType" />
This tiny bit of XML will automatically create beans for all classes in the "com.habuma.dao" package, auto-wiring their properties "byType". Only 3 short lines (could be fit on one line) replace 18 lines of XML for 6 DAOs. And here's the kicker: If I add another DAO (or even 1000 of them) to the "com.habuma.dao" package, I don't have to add any more XML! Those three lines will handle all of them, so long as they're in the "com.habuma.dao" package.
Chris has written more about Arid on his blog. Check it out!