【问题标题】:Can not access bundle context from JSP in CQ5.5无法从 CQ5.5 中的 JSP 访问捆绑上下文
【发布时间】:2013-03-17 17:39:47
【问题描述】:

我创建了一个 OGI 包,名为:

com.sdl.ws.integration.profserv.webservice.connector.server.external.beans

我可以在下面看到捆绑包:

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

以下是我的 JSP 代码,我正在使用它来访问 bundlecontext

 <%@ page import="org.osgi.framework.BundleContext"%>  
 <%@ page import="org.osgi.framework.FrameworkUtil"%>
 <%@ page import="com.sample.osgi.components.FormattingServiceImpl.*"%>  
 <%@ page import="org.osgi.service.cm.ConfigurationAdmin"%>
 <%@ page import="org.osgi.service.cm.Configuration"%>   
  <%@ page import="org.osgi.service.packageadmin.PackageAdmin"%>   

 <%
    BundleContext bundleContext =      FrameworkUtil.getBundle(FormattingServiceImpl).getBundleContext();  

  %>

我收到以下错误:FormattingServiceImpl 无法解析

我尝试使用多种方式导入 jar,但没有任何效果,

这是我的捆绑包的配置结构:

我被困在如何从 JSP 访问捆绑上下文的问题上,有人有任何建议/更正吗?

【问题讨论】:

    标签: jsp osgi aem osgi-bundle


    【解决方案1】:

    您可能只是缺少 .class 来引用您的 FormattingServiceImpl 类 - 以下对我来说适用于裸 Apache Sling 实例,使用 Sling 的 Resource 接口而不是 FormattingServiceImpl 但具有相同的模式:

      <%@ page import="org.osgi.framework.BundleContext"%>  
      <%@ page import="org.osgi.framework.FrameworkUtil"%>
      <%@ page import="org.apache.sling.api.resource.Resource"%>  
    
      <%
        BundleContext bc = FrameworkUtil.getBundle(Resource.class).getBundleContext();
      %>
    
      <%= bc %>
    

    话虽如此,在 JSP 脚本中获取 BundleContext 的 IMO 很少有有效用例,我首先会质疑是否需要这样做。

    此外,您的代码似乎表明 FormattingServiceImpl 是一个实现类,并且由定义它的包导出,这通常也是一个坏主意。一般来说,bundle 应该只导出包含它们提供的服务的接口的包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2017-09-03
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多