Getting OSGi services from a bundle in Sling/CQ

前端 未结 3 1623
野趣味
野趣味 2021-02-08 04:21

I am using Day CQ. I want to store some data in a SQL Server DB, using the connection pool available in the Felix console. I can do this from a JSP, by using the \"sling\" objec

3条回答
  •  旧巷少年郎
    2021-02-08 04:44

    To get a service from a java OSGi component you don't need the SlingScriptHelper, you can either use the BundleContext.getService(...) method, or use SCR annotations to let SCR inject the service in your component.

    As an example, you can look at how some components in Sling's Slingbucks sample use SCR annotations, the ConfirmedOrdersObserver class for example gets the SlingRepository in this way:

       @Reference
       private SlingRepository repository;
    

    See http://felix.apache.org/site/apache-felix-maven-scr-plugin.html for the Maven plugin that handles these annotations.

提交回复
热议问题