Monday, March 30, 2015

Grails dumping SQL statements

Edit the DataSource.groovy

dataSource {
   dbCreate = ...
   url = ...
   logSql = true

And in the Config.groovy:

log4j = {
   debug 'org.hibernate.SQL'
   trace 'org.hibernate.type'

Wednesday, March 25, 2015

Grails JSON encoding applyCodec

I had some data that I wanted to render in the GSP page, however, by default single quotes were being encoded as


To prevent grails from encoding your output, wrap it in the undocumented  applyCodec tag as follows:

var selectedItems = <g:applyCodec encodeAs="none">${data as grails.converters.JSON}</g:applyCodec>


Monday, March 9, 2015

Starting elasticsearch "Too small initial heap for new size specified"

When starting elasticserach for the first time I received the following error:

Error occurred during initialization of VM
Too small initial heap for new size specified

Added the following to elasticsearch.bat

set JAVA_OPTS=-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m -Xmx1536m -XX:NewSize=1024m -XX:MaxNewSize=1024m -XX:PermSize=768m -XX:MaxPermSize=768m -XX:+DisableExplicitGC

Sunday, March 1, 2015

Upgrading from Grails 2.3.x to Grails 2.4.x

Upgrading from Grails 2.3.x to Grails 2.4.x

Previous upgrades in Grails were simple where a single 'upgrade' command  made it extremely easy.
However, it's not quite as easy for upgrades to Grails 2.4.4.
There's a reference guide on how to do the upgrade which does require a bit of tinkering found here:

If you rely on several plugins there's a good chance you'll need to update nearly all of your plugins to the recent version. To find the latest plugin versions do a search here:

Spring security

Furthermore, if you rely on the spring-security plugin, you may need to upgrade all the package names as they have changed:



Also if you use the @Secured annotation update the import to be:

To find other package name changes, double check the source code here:

Furthermore, the recent version of the plugin spring-security-core:2.0-RC4 by default relies on pessimistic locking ( Since my app is mostly public, I've added 2 configuration parameters to the Config.groovy file

// allow public access:
grails.plugin.springsecurity.rejectIfNoRule = false
grails.plugin.springsecurity.fii.rejectPublicInvocations = false

I had forgotten to update the spring-security configuration parameters as the names have changed which resulted in the following error:

Message: Dynamic method get<Artefact>Class(artefactName) requires a single String parameter
    Line | Method
->>   57 | loadUserByUsername    in grails.plugin.springsecurity.userdetails.GormUserDetailsService
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     49 | getGrantedAuthorities in grails.plugin.springsecurity.ldap.userdetails.DatabaseOnlyLdapAuthoritiesPopulator
|     76 | attemptAuthentication in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     49 | doFilter              in     ''
|     82 | doFilter . . . . . .  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker             in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run                   in java.lang.Thread

For example, the parameter for grails.plugins.springsecurity.providerNames has changed to grails.plugin.springsecurity.providerNames. Notice that 'plugins' has changed to 'plugin'


LDAP spring security

The names of the configuration parameters for the latest LDAP 2.0-RC2 have changed. At the time of writing, there was also no updated documentation (since it was a release candidate). However, if you need to see what configuration parameters look like, have a look at the source code:

Notice that 'plugins' has changed to 'plugin' 

Remove grailsResourceLoader from applicationContext.xml

Update the web-app/WEB-INF/applicationContext.xml file by removing any references to grailsResourceLoader to be as follows:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

    <bean id="grailsApplication" class="org.codehaus.groovy.grails.commons.GrailsApplicationFactoryBean">
        <description>Grails application factory bean</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />

    <bean id="pluginManager" class="org.codehaus.groovy.grails.plugins.GrailsPluginManagerFactoryBean">
        <description>A bean that manages Grails plugins</description>
        <property name="grailsDescriptor" value="/WEB-INF/grails.xml" />
        <property name="application" ref="grailsApplication" />

    <bean id="grailsConfigurator" class="org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator">
            <ref bean="grailsApplication" />
        <property name="pluginManager" ref="pluginManager" />

    <bean id="characterEncodingFilter" class="org.springframework.web.filter.CharacterEncodingFilter">
        <property name="encoding">


No suitable classloader found for 'Grab'

Rather than trying to load the dependencies at runtime, try adding the dependencies to grails-app/conf/BuildConfig.groovy


Database drivers

 Even though I had the mySQL driver installed in the lib folder, there was an error when trying to run the app:
ClassNotFoundException: com.mysql.jdbc.Driver

To get it working, I added the library to the BuildConfig.groovy file as follows:
runtime 'mysql:mysql-connector-java:5.1.24'


Sitemesh errors:

When starting up the application, I got a sitemesh error as follows:

2015-03-02 09:43:47,277 [localhost-startStop-1] ERROR [localhost].[/mutations]  - Exception starting filter sitemesh
Message: org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter
    Line | Method
->>   59 | findClass in org.grails.plugins.tomcat.ParentDelegatingClassLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    423 | loadClass in java.lang.ClassLoader
|    356 | loadClass in     ''
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread
Error |
 It appears that sitemesh has been removed and any references to it should be removed as well.
Under the folder /src/templates/war/web.xml, edit the file to remove the following XML snippets:




Broken legacy GSP views

In the BuildConfig.groovy file, check to make sure that the asset-pipline is not included

java.lang.ClassNotFoundException: org.springframework.mock.web.MockHttpServletRequest

It seems building a production WAR file relies on a missing MockHttpServletRequest class. The bug has been raised in this link:

The workaround is to include the spring-test JAR file in your dependencies as follows:

runtime 'org.springframework:spring-test:3.2.13.RELEASE'


Conflicting module versions

When trying to run the application you may get the following error:

Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions

To fix this issue do the following:
  1. open eclipse go to "Run as" then "Run Configurations"
  2. choose "Environment" tab , then choose "replace native environment with specified environment "