Created
March 23, 2022 16:31
-
-
Save cruzer45/e887a3914e8a87db7041752635d26c96 to your computer and use it in GitHub Desktop.
Using a service in Grails Bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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