OSGi ConfigurationAdmin服务 [英] OSGi ConfigurationAdmin Service

查看:145
本文介绍了OSGi ConfigurationAdmin服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有两种方法可以从OSGi服务注册表中获取Configuration Admin服务.首先实例化BundleContext,然后从中获取ServiceReference,然后从中获取ConfigurationAdmin:

There seem to be 2 ways to get the Configuration Admin service from the OSGi service registry. One by instantiating BundleContext, then getting ServiceReference from that, then ConfigurationAdmin from that:

BundleContext bc = FrameworkUtil.getBundle(ManagedService.class).getBundleContext();
ServiceReference ca = bc.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(ca);

另一种方法是使用Blueprint并简单地创建对ConfigurationAdmin的引用,如下所示,然后在Bean中进行引用:

Another by using Blueprint and simply creating a reference to ConfigurationAdmin, as shown below, then referencing that in a bean:

<reference id="configAdmin" interface="org.osgi.service.cm.ConfigurationAdmin" />

这两种方法是否等效?还是前一种方法提供了后者没有提供的任何东西?是否有任何蓝图参考文档描述了实例化ConfigurationAdmin的操作(似乎找不到任何内容)?

Are these 2 approaches equivalent? Or does the former approach provide anything the latter doesn't? And is there any Blueprint reference documentation that describes what it's doing to instantiate ConfigurationAdmin (can't seem to find any)?

推荐答案

这些不是实例化" Configuration Admin服务.它们是从OSGi服务注册表中获取Configuration Admin服务的服务对象的方法.两种方式都将返回相同的服务对象.第一种方法使用低级OSGi API与OSGi服务注册表进行交互.第二种方法使用蓝图.

These are not "instantiating" a Configuration Admin service. They are ways of getting the service object for the Configuration Admin service from the OSGi service registry. Both ways would return the same service object. The first way uses the low-level OSGi API to interact with the OSGi service registry. The second way uses Blueprint.

关于蓝图,我建议在OSGi中使用声明式服务进行依赖项注入.

Regarding Blueprint, I would instead recommend using Declarative Services for dependency injection in OSGi.

这篇关于OSGi ConfigurationAdmin服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆