Skip to content

Instantly share code, notes, and snippets.

@cruzer45
Created March 25, 2022 03:52
Show Gist options
  • Save cruzer45/eea64a92d5550f9303e23385e3691006 to your computer and use it in GitHub Desktop.
Save cruzer45/eea64a92d5550f9303e23385e3691006 to your computer and use it in GitHub Desktop.
Using a service in Grails Bootstrap
import org.springframework.web.context.support.WebApplicationContextUtils
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