Java 如何在Sling中创建JobConsumer?

Java 如何在Sling中创建JobConsumer?,java,aem,apache-felix,sling,Java,Aem,Apache Felix,Sling,根据ApacheSling官方站点(),这是编写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 @S

根据ApacheSling官方站点(),这是编写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和@Property都是不推荐使用的注释。 我想知道创建JobConsumer的正确方法。
有人知道如何编写与上述内容等效的代码吗?

AEM中不推荐使用scr注释,建议以后使用官方OSGi声明性服务注释。在使用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;
    }
}