Custom init in test / development mode in Grails

I want to run a specific login in the BootStrap class, depending on the development or testing mode currently.

How can i do this?

+6
grails groovy
source share
3 answers
import grails.util.Environment class BootStrap { def init = { servletContext -> def currentEnv = Environment.current if (currentEnv == Environment.DEVELOPMENT) { // do custom init for dev here } else if (currentEnv == Environment.TEST) { // do custom init for test here } else if (currentEnv == Environment.PRODUCTION) { // do custom init for prod here } } def destroy = { } } 
+6
source share

From the documentation :

 class Bootstrap { def init = { ServletContext ctx -> environments { production { // prod initialization } test { // test initialization } development { // dev initialization } } } ... } 
+14
source share

from official documents

Software Discovery

In your code, for example, in a Gant script or in the bootstrap class, you can find the environment using the GrailsUtil class:

 import grails.util.GrailsUtil ... switch(GrailsUtil.environment) { case "development": configureForDevelopment() break case "production": configureForProduction() break 
0
source share

All Articles