Skip to content

Instantly share code, notes, and snippets.

@cruzer45
Created March 23, 2022 16:31
Show Gist options
  • Save cruzer45/e887a3914e8a87db7041752635d26c96 to your computer and use it in GitHub Desktop.
Save cruzer45/e887a3914e8a87db7041752635d26c96 to your computer and use it in GitHub Desktop.
Using a service in Grails Bootstrap
class BootStrap {
def init = { servletContext ->
def springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext)
println "Initializing..."
def service = springContext.getBean("notificationService")
service.sendAdminNotification("[UP] started")
}
/**
* Note: this is not guaranteed to be called by the servlet container
*/
def destroy = { servletContext ->
printn "De-initializing..."
def springContext = WebApplicationContextUtils.getWebApplicationContext(servletContext)
if (Environment.current == Environment.DEVELOPMENT) {
} else if (Environment.current == Environment.TEST) {
} else if (Environment.current == Environment.PRODUCTION) {
def service = springContext.getBean("notificationService")
service.sendAdminNotification("[DOWN] destroyed")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment