简体   繁体   English

如何在扩展WCMUse类的模型类中从AEM 6.1的OSGI配置中读取属性

[英]How to read property from OSGI configuration in AEM 6.1 in model class which extends WCMUse class

I am extending my model class to WCMUse class to write my business logic. 我将模型类扩展到WCMUse类以编写我的业务逻辑。 I have osgi configuration which has couple of properties. 我有具有几个属性的osgi配置。 I want to read one of the property in my model class. 我想读取模型类中的属性之一。 I am not sure how to get the handle of osgi configuration in WCMUse class. 我不确定如何在WCMUse类中获取osgi配置的句柄。 Any pointers will be highly appreciated. 任何指针将不胜感激。

Adding the answer for future references. 添加答案以供将来参考。

You can use the #getSlingScriptHelper() method of the WCMUse class to get an handle of the SlingScriptHelper . 您可以使用#getSlingScriptHelper()的方法WCMUse类来获得的手柄SlingScriptHelper This is the same sling object that is available through inclusion of global.jsp in traditional JSP scripts. 通过在传统JSP脚本中包含global.jsp ,可以使用相同的sling对象。

You can then call #getService() method of the SlingScriptHelper to look up the desired OSGi Service. 然后,您可以调用#getService()方法来查找所需的OSGi服务。

The following code snippet can be used in the model to get the service configuration 可以在模型中使用以下代码片段来获取服务配置

getSlingScriptHelper().getService(<<Configuration Service>>.class)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM