简体   繁体   English

吊带如何使用osgi捆绑

[英]how osgi bundles are used by sling

I am just starting on Apache sling and CQ5 development. 我刚开始使用Apache sling和CQ5开发。 There is this concept of using OSGI bundles in Sling. 在Sling中有使用OSGI包的概念。

I can't find out how the sling framework actually interacts with these bundles and where does the response from bundles go ? 我不知道吊索框架实际上如何与这些捆绑包进行交互以及捆绑包的响应在哪里?

OSGi is module framework and service platform used by Sling and the CQ5 product. OSGi是Sling和CQ5产品使用的模块框架和服务平台。 Sling itself is comprised of a series of bundles hosted within the Felix OSGi container. Sling本身由Felix OSGi容器中托管的一系列包组成。 Bundles are a collection group of components/services and java classes managed by the container. Bundle是由容器管理的组件/服务和java类的集合组。 The bundle can specify which packages will be imported, exported and also the versions of those dependencies. 捆绑包可以指定将导入,导出哪些包以及这些依赖项的版本。

There are a number of ways that you can interact with OSGi from Sling. 您可以通过多种方式与Sling中的OSGi进行交互。 From a JSP/JSP you can use the sling object (of type SlingScriptHelper ), which is most likely available in your JSP page if you have included the following line: 在JSP / JSP中,您可以使用sling对象( SlingScriptHelper类型),如果您包含以下行,则最有可能在JSP页面中使用该对象:

<%@include file="/libs/foundation/global.jsp"%>

in your component or have the following: 在您的组件中或具有以下内容:

<cq:defineObjects> 

You can use it like so: 您可以像这样使用它:

QueryBuilder queryBuilder = sling.getService(QueryBuilder.class);

Additionally, if you have your own OSGi components (eg Servlet, Service, etc) you can inject references to other OSGI components/services using SCR annotations. 此外,如果您有自己的OSGi组件(例如Servlet,Service等),则可以使用SCR注释注入对其他OSGI组件/服务的引用。 Bertrand describes this in his answer to Getting OSGi services from a bundle in Sling/CQ . Bertrand在他从Sling / CQ中的捆绑中获取OSGi服务的答案中描述了这一点。 Effectively this means adding the @Reference annotation to your OSGI component variables in your components, like so: 实际上,这意味着将@Reference注释添加到组件中的OSGI组件变量,如下所示:

 @Reference
 private SlingRepository repository;

When your component is loaded, then the reference will be injected by the OSGi container. 加载组件后,OSGi容器将引用该引用。

A bundle doesn't have a response as such. 捆绑包没有这样的响应。 A deployed bundle should be visible in the system console: 部署的捆绑包应该在系统控制台中可见:

http://localhost:4502/system/console/bundles

with its components, services & configuration declared here: 其组件,服务和配置在此处声明:

http://localhost:4502/system/console/services
http://localhost:4502/system/console/components
http://localhost:4502/system/console/configMgr

(Replace localhost:4502 with your own CQ server host:port) (将localhost:4502替换为您自己的CQ服务器主机:端口)

Once you have obtained a reference to a component, then you can call the methods on that and use the return values from those calls. 获得对组件的引用后,可以调用该方法并使用这些调用的返回值。

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

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