Created
March 25, 2022 03:52
-
-
Save cruzer45/eea64a92d5550f9303e23385e3691006 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
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