Scala中的OSGi注释(激活,参考,组件)

问题描述 投票:1回答:1

[我正在尝试用Scala编写OSGi服务(大多数其他服务/捆绑都是用Java编写的,我在语法上有些挣扎。

通常在Java中,可以在这样的构造函数上使用@Activate批注:

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;

@Component(configurationPid = "PID", service=AgentService.class, immediate=true)
public class AgentServiceImpl implements AgentService {
   @Activate
    public AgentServiceImpl(@Reference Service1 service1, @Reference Service2 service2) {
  // ...
}

在Scala中,它看起来应该像这样:

import org.osgi.service.component.annotations.{Activate, Component, Deactivate, Reference}

@Component(
  configurationPid = "PID",
  service = Array(classOf[AgentService]),
  immediate = true)
class AgentServiceImpl @Activate() (@Reference service1: Service1, 
                                    @Reference service2: Service2) implements AgentService {
   // ...
}

当我尝试使用Scatter编译此Scala代码时,出现了以下错误消息:

error  : In component xxx.xxxx.xx.xx.agent.AgentServiceImpl , multiple references with the same name: service1. Previous def: xxx.xxxx.xx.xx.service.Service1, this def:
error  : In component xxx.xxxx.xx.xx.agent.AgentServiceImpl , multiple references with the same name: service2. Previous def: xxx.xxxx.xx.xx.service.Service2, this def:

发生这种情况是因为我有关注释的语法是错误的吗?我对此@Activate()位不太确定。在Java中,我不需要在这里使用方括号-但如果没有Scala,它就无法编译。

有人知道一个示例项目试图做类似的事情吗?

scala osgi apache-felix
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.