Posts Tagged ‘grails’

Custom Grails Environment Snag

Tuesday, October 21st, 2008

When creating custom Grails environments, you can’t use hyphens or Grails will complain with the following:

MissingMethodException: No signature of method: groovy.util.ConfigObject.minus() is applicable for argument types: (null) values: {null}

Change the hyphen to say an underscore, and you’re good to go.

Grails Reserved Word, ‘Position’

Sunday, August 31st, 2008

It turns out the word “position” is a reserved word in Grails. If you use this as one of your domain entity’s properties, Grails will not be able to create the table for your domain class.

Grails, Constructor Injection, and Spring Bean Builders

Friday, July 18th, 2008

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