I don’t know, when I was thinking about a name for the post, all the terms I was coming up with made me think of those coffee freaks at StarBucks ordering their custom cup o’ Joe.
Anyway, just wanted to share something that made my ColdSpring.xml file much cleaner and easier to manage/read. I use the AOP feature of the ColdSpring framework to add logging advice to my most heavily used components. This led to many, many, many beans in my config file as I had one for the gateway, one for the service and one for the proxy factory which wrapped around the service.
<bean id="VialDetailGateway" class="charm.model.request.item.vial.VialDetailGateway">
<constructor-arg name="transfer">
<bean factory-bean="transfer" factory-method="getTransfer" />
</constructor-arg>
</bean>
<bean id="VialDetailTarget" class="charm.model.request.item.vial.VialDetailService">
<constructor-arg name="transfer">
<bean factory-bean="transfer" factory-method="getTransfer" />
</constructor-arg>
<constructor-arg name="VialDetailGateway">
<ref bean="VialDetailGateway"/>
</constructor-arg>
<constructor-arg name="datasource">
<bean factory-bean="transfer" factory-method="getDatasource" />
</constructor-arg>
</bean>
<bean id="VialDetail" class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="VialDetailTarget" />
</property>
<property name="interceptorNames">
<list>
<value>exceptionLoggingAdvisor</value>
</list>
</property>
</bean>
Then a few months ago, I was trolling the ColdSpring discussion boards and came across a post from Barney Boisvert where he mentions that he uses anonymous inner beans when creating the AOP proxy in order to prevent the creation of the actual service component.
It sounded like a good idea, so after implementing that, it reduced the amount of bean definitions in my config file by, you guessed it, 33%.
<bean id="VialDetailGateway" class="charm.model.request.item.vial.VialDetailGateway">
<constructor-arg name="transfer">
<bean factory-bean="transfer" factory-method="getTransfer" />
</constructor-arg>
</bean>
<bean id="VialDetail" class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="charm.model.request.item.vial.VialDetailService">
<constructor-arg name="transfer">
<bean factory-bean="transfer" factory-method="getTransfer" />
</constructor-arg>
<constructor-arg name="VialDetailGateway">
<ref bean="VialDetailGateway"/>
</constructor-arg>
<constructor-arg name="datasource">
<bean factory-bean="transfer" factory-method="getDatasource" />
</constructor-arg>
</bean>
</property>
<property name="interceptorNames">
<list>
<value>exceptionLoggingAdvisor</value>
</list>
</property>
</bean>
Then it hit me today. I never directly access my gateway components, since there is a method in the service component that proxies each gateway method. If I don’t use the gateway beans, I thought, why on Earth don’t I just make them inner beans of the service definition?
In the end, I’ve reduced the amount of bean definitions by, you guessed right again, 66% and now just have one bean definition for each component. Nice and clean, just the way I like it.
<bean id="VialDetail" class="coldspring.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="charm.model.request.item.vial.VialDetailService">
<constructor-arg name="transfer">
<bean factory-bean="transfer" factory-method="getTransfer" />
</constructor-arg>
<constructor-arg name="VialDetailGateway">
<bean class="charm.model.request.item.vial.VialDetailGateway">
<constructor-arg name="transfer">
<bean factory-bean="transfer" factory-method="getTransfer" />
</constructor-arg>
</bean>
</constructor-arg>
<constructor-arg name="datasource">
<bean factory-bean="transfer" factory-method="getDatasource" />
</constructor-arg>
</bean>
</property>
<property name="interceptorNames">
<list>
<value>exceptionLoggingAdvisor</value>
</list>
</property>
</bean>
Leave a reply