我有以下声明式服务:

@Component(
    immediate = false,
    property={"propA=valueA","propB=valueB","propC=valueC"},
    scope=ServiceScope.SINGLETON
)
public class ServiceImpl implements ServiceI{...}


这是我通过propA(手动)找到此服务所需的代码:

String filter = "(&(objectClass=" + ServiceI.class.getName() + ")(propA=valueA))";
ServiceReference[] serviceReferences = bundleContext.getServiceReferences((String)null,filter);
ServiceI service=(ServiceI) bundleContext.getService(serviceReferences[0]);


如何获得找到的服务的propB的valueB和propC的valueC?

最佳答案

您可以使用getProperty实例的ServiceReference

Object propBValue = serviceReference.getProperty("propB");

关于java - OSGI:从DS获取属性信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38816369/

10-11 02:16