Grails 3.3 - 如何替换已弃用的服务工件?

Grails 3.3 - How to replace deprecated Service artefact?

我即将把我的 Grails 3.2 网络应用程序升级到 3.3 版。

特别是,我创建了一个 BaseService 抽象 class(位于 /src/groovy)提供了几个辅助方法,我的大部分 Grails 服务都扩展了 BaseService

import grails.artefact.Service

abstract class BaseService implements Service {
    ...
}

我注意到 Grails 3.3 grails.artefact.Service 及其超级 class grails.events.Events.

已被弃用

我可以用什么代替 Service 来避免保留对已弃用 class 的引用?

弃用是因为 New Events API and Async Framework。如果你阅读了 grails 3 的文档,你会发现:

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.

因此,如果您的 implements Service 用于使用 Events,那么您已经 使用 grails 3 asyncevents 更新您的事件实现 插入。查看异步框架文档#events 部分。