如何在 Sling 中创建 JobConsumer?

How to create JobConsumer in Sling?

根据Apache Sling官网(https://sling.apache.org/documentation/bundles/apache-sling-eventing-and-job-handling.html#job-consumers),JobConsumer的写法是这样的

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;

@Component
@Service(value={JobConsumer.class})
@Property(name=JobConsumer.PROPERTY_TOPICS, value="my/special/jobtopic",)
public class MyJobConsumer implements JobConsumer {

    public JobResult process(final Job job) {
        // process the job and return the result
        return JobResult.OK;
    }
}

但是@Service 和@属性 都是不推荐使用的注解。 我想知道创建 JobConsumer 的正确方法。 有谁知道如何编写与上述等效的代码?

AEM 中已弃用 scr 注释,建议今后使用官方 OSGi 声明性服务注释。 seminar by Adobe 关于使用 OSGi R7 注释。

新的写法是

import org.osgi.service.component.annotations.Component;
import org.apache.sling.event.jobs.Job;
import org.apache.sling.event.jobs.consumer.JobConsumer;

@Component(
    immediate = true,
    service = JobConsumer.class,
    property = {
        JobConsumer.PROPERTY_TOPICS +"=my/special/jobtopic"
    }
)
public class MyJobConsumer implements JobConsumer {

    public JobResult process(final Job job) {
        // process the job and return the result
        return JobResult.OK;
    }
}