11.2.1 Consuming Events - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.9
11.2.1 Consuming Events
There are several ways to consume an event. As mentioned previously services and controllers implement the Events trait.TheEvents
trait provides several methods to register event consumers. For example:on("myEvent") { println "Event fired!" }
Events
trait and ensure the class is registered as a Spring bean.For example given the following class:import grails.events.* import javax.annotation.*class MyClass implements Events { @PostConstruct void init() { on("myEvent") { println "Event fired!" } } }
doWithSpring
in your Application
class to register it as a Spring bean (or annotate it with Component
):Closure doWithSpring() { {-> myClass(MyClass) } }