We can use PostConstruct with Grails Services and injected Spring Beans. This PostConstruct annotation can be used to annotate a method which needs to be executed after dependency injection to perform any initialization. [code] import javax.annotation.PostConstruct class PostConstructDemoService { @PostConstruct private...
While working on my project using Grails 2.0.3, I was getting java.lang.OutOfMemoryError with grails run-war even when my JAVA_OPTS are set. Then while going through documentation and this thread i found how to set jvm args for grails run-war. Just add this code in your BuildConfig.groovy and you are done. [code]...
In one of our project we needed to maintain history of domain objects when they are updated. We saw Grails Audit Logging Plugin as a good candidate. But later, found that it doesn't take care of persistent collections. So with help of my colleague Vivek and this Stack Overflow thread, we extended this plugin without making it inline, to...
Hi All, Today i found how to specify default package for all Grails artefacts, would like to share with you. By default when we create any domain, controller or any other artefact, It takes application name as default package. If you want to change that just define grails.project.groupId property in your Config.groovy. [code]...
The CodeNarc plugin provides static code analysis using CodeNarc library. CodeNarc analyzes Groovy code for defects, bad practices, inconsistencies, style issues etc. CodeNarc provides a Groovy DSL for defining RuleSets. Install CodeNarc plugin into you grails project. Now create one groovy file say CustomRules.groovy and add following...
In one of my project, I was in need to return multiple variables from a method. I searched and found very good Groovy way for 'Multiple Assignment', This allows us to assign multiple variables at once. [groovy]def (str1,str2,str3) = ['Groovy','and','Grails'] assert str1 == 'Groovy' && str2 == 'and' &&...
Grails applications can define their own codecs and Grails will load them along with the standard codecs. A custom codec class must be defined in the grails-app/utils/ directory and the class name must end with 'Codec'. For more information see Dynamic Encoding Methods. [java] import java.security.MessageDigest import...