Table of contents
How To Check If Environment is Test, Development, or Production in Grails
Bootstrap
import grails.util.Environment
class BootStrap {
def init = { servletContext ->
if (Environment.current == Environment.DEVELOPMENT) {
// insert Development environment specific code here
} else if (Environment.current == Environment.TEST) {
// insert Test environment specific code here
} else if (Environment.current == Environment.PRODUCTION) {
// insert Production environment specific code here
}
}
}
Controller
import grails.util.Environment
class SomeController {
def someAction() {
if (Environment.current == Environment.DEVELOPMENT) {
// insert Development environment specific code here
} else if (Environment.current == Environment.TEST) {
// insert Test environment specific code here
} else if (Environment.current == Environment.PRODUCTION) {
// insert Production environment specific code here
}
render "Environment is ${Environment.current}"
}
}
View/GSP
<g:if env="development">
We are in Development Mode
</g:if>
<g:if env="production">
We are in Production Mode
</g:if>
<g:if env="test">
We are in Test Mode
</g:if>