ManagedService 不会从文件安装中调用

ManagedService won't get called from File Install

我有这样的 Felix 设置:

   ID|State      |Level|Name
    0|Active     |    0|System Bundle (5.0.1)
    1|Active     |    1|Apache Felix Bundle Repository (2.0.4)
    2|Active     |    1|Apache Felix Configuration Admin Service (1.8.8)
    3|Resolved   |    1|Apache Felix File Install (3.5.0)
    4|Active     |    1|Apache Felix Gogo Command (0.14.0)
    5|Active     |    1|Apache Felix Gogo Runtime (0.16.2)
    6|Active     |    1|Apache Felix Gogo Shell (0.10.0)
    7|Active     |    1|g.db OSGi Bundle (1.0.0)

g.db 包基本上是这样做的:

public class Activator implements BundleActivator, ManagedService {

ServiceRegistration sr;

public void updated(Dictionary dict) throws ConfigurationException {
    System.err.println("\nupdated " + this);
}

public void start(BundleContext context) throws Exception {

    System.err.println("\nstart " + this);

    Dictionary props = new Hashtable();
    props.put(Constants.SERVICE_PID, "db");
    sr = context.registerService(ManagedService.class.getName(), this, props);

}
}

如果我在 ./load 中修改 db.cfg,我正在等待 updated() 被调用。但是不会。

g! inspect cap service 7
g.db [7] provides:
------------------------------------
service; org.osgi.service.cm.ManagedService with properties:
   service.bundleid = 7
   service.id = 28
   service.pid = db
   service.scope = singleton

文件安装正在监视正确的文件。我在修改 db.cfg:

时收到日志消息
Updating configuration from db.cfg

我提高了配置管理服务的日志级别并得到这个:

*DEBUG* Scheduling task Update: pid=db
*DEBUG* Running task Update: pid=db
*DEBUG* UpdateConfiguration(db) scheduled
*DEBUG* Updating configuration db to revision #3
*DEBUG* No ManagedService[Factory] registered for updates to configuration db

我的服务注册似乎有问题 (?)


最后 NB 项目的 POM 中出现错误:我在 compile 范围内使用了 org.osgi.compendium 工件。更改为 provided 范围并且它有效。

编译或提供范围通常应该没有区别...除非您还嵌入了所有编译范围依赖项。

在这种情况下,您在嵌入规范包时遇到的错误是正常的。所以你的包看到的包和配置管理服务使用的包是不同的。因此您的 ManagedService 将不会被配置管理服务实现获取。