Grails, Constructor Injection, and Spring Bean Builders

Had a run-in with Grails and trying to wire up some custom beans using Grails’s Spring Bean Builder DSL mechanism. I was wiring up an instance of the Apache HttpClient object, which can be constructed with HttpClientParams and/or HttpConnectionManager. Now the Grails BB syntax expects the first argument to be the type you’re wiring, followed by the parameters to pass into the constructor. Something like this:
httpClient(org.apache.commons.httpclient.HttpClient, defaultGlobalHttpConnectionManager)

Where httpClient is the bean name/id, org.apache.commons.httpclient.HttpClient is the type we’re wiring, and defaultGlobalHttpConnectionManager is some custom implementation of the HttpConnectionManager.

When using this Bean Builder syntax, Grails gets consfused about the argument ordering and is unable to create its Grails Application Context. I also tried the following which didn’t work either.
httpClient(org.apache.commons.httpclient.HttpClient, null,
defaultGlobalHttpConnectionManager)

I don’t know if you can explicitly set the arguments the same way you can in the standard XML wiring approach. My solution was then to use the tried and true method.

<bean id="defaultGlobalHttpConnectionManager"
class="com.site.commons.http.GlobalHttpConnectionManager"
destroy-method="shutDown" lazy-init="default" autowire="default"
dependency-check="default">
<property name="soTimeout">
<value>20000</value>
</property>
<property name="connectionTimeout">
<value>20000</value >
</property>
</bean>


<bean id="httpClient"
class="org.apache.commons.httpclient.HttpClient" lazy-init="default"
autowire="default"
dependency-check="default">
<constructor-arg ref="defaultGlobalHttpConnectionManager" />
</bean>

Resources:
http://grails.org/doc/1.0.x/
http://hc.apache.org/httpclient-3.x/apidocs/index.html

Tags: ,

2 Responses to “Grails, Constructor Injection, and Spring Bean Builders”

  1. THEODORE Says:


    MedicamentSpot.com. Canadian Health&Care.No prescription online pharmacy.Special Internet Prices.Best quality drugs. High quality drugs. Buy pills online

    Buy:Viagra.Cialis Soft Tabs.Levitra.Soma.Super Active ED Pack.Viagra Super Active+.Propecia.Viagra Professional.Cialis Professional.Cialis.Zithromax.VPXL.Tramadol.Cialis Super Active+.Maxaman.Viagra Soft Tabs.Viagra Super Force….

  2. atx26t Says:

    AT&T http://shewlettozipasb.05KIAPARTS.US/tag/AT&T+Help+atx26t+tilt/ : AT&T…

    tilt…

Leave a Reply