Search code examples
grailsservicedeprecatedgrails-3.3

Grails 3.3 - How to replace deprecated Service artefact?


I'm about to upgrade my Grails 3.2 web-app to version 3.3.

In particular, I created a BaseService abstract class (located in /src/groovy) providing several helper methods, and most of all my Grails services extend BaseService.

import grails.artefact.Service

abstract class BaseService implements Service {
    ...
}

I noticed that with Grails 3.3 grails.artefact.Service was deprecated, along with its superclass grails.events.Events.

What can I use in place of Service to avoid keeping references to deprecated classes?


Solution

  • The deprecation is because of New Events API and Async Framework. If you read the documentation of grails 3, you can find:

    In order to support multiple different asynchronous and reactive frameworks Grails 3.3 has been decoupled from Reactor 2.x and an abstract EventBus notation added.

    The EventBus interface provides the foundation and multiple implementations including GPars and RxJava.

    A new set of annotations usable in services classes and regular Spring beans can be leveraged to publish and consume events:

    Publisher - A transformation that transforms a method ensuring the return value is published as an event

    Subscriber - A transformation that transforms a method to listen for an event.

    So if your implements Service was for using Events, then you've to update your events implementation using grails 3 async and events plugin. Check out the Async framework documentation #events part.