将蓝图OSGi服务注入JSF

将蓝图OSGi服务注入JSF

本文介绍了将蓝图OSGi服务注入JSF/PrimeFaces bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于顶级OSGi和Karaf服务器的项目.对于依赖项注入,我们使用Aries Blueprint.该项目的主要部分是Apache Camel路由和集成的东西,但是现在我需要创建一些维护Web界面.因此,我尝试使用JSF-PrimeFaces实现.我能够创建一些演示,可以在Karaf下的OSGi中工作,没关系.

I have a project built on top OSGi and Karaf server. For dependency injection we are using Aries Blueprint.The main part of the project is a Apache Camel routes and integration things, but now I need to create some maintenance web interface.So I give a try to JSF - PrimeFaces implementation. I was able to create some demo, which works in OSGi under Karaf, that's ok.

现在,我想知道是否可以在这里使用Blueprint,以引用我们已经拥有的一些OSGi服务并将该服务注入JSF Bean,以便我们可以从已编写的代码中受益.

Now I'd like to know if it's possible to use Blueprint here, to reference some already existing OSGi services we have and inject the service into JSF Bean, so we can benefit from already written code.

可以帮我吗?

推荐答案

我们通过以下方式解决了此问题:

We solved this in the following way:

  • 我们创建了一个监听器,该监听器:
    • 创建一个ServiceTracker,以跟踪附加到同一捆绑包的BlueprintContainer服务
    • 将servicetracker放入ServletContext属性
    • We created a listener that:
      • Creates a ServiceTracker that tracks the BlueprintContainer service attached to the same bundle
      • Puts the servicetracker into the ServletContext attributes

      我们的侦听器类: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/servlet/ServiceLoaderListener.java

      我们的EL解析器类: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/el/OsgiELResolver.java

      Our EL resolver class: https://source.everit.biz/svn/everit-util/trunk/core/src/main/java/org/everit/util/core/el/OsgiELResolver.java

      用户/密码:访客/访客

      User/pass: guest/guest

      注册定制的el-resolver后,将以在蓝图容器内搜索组件实例ID的方式评估所有el-expression.如果您说faces-config.xml中有一个值为#{myComponent}的bean属性,它将在BlueprintContainer中进行搜索.

      After you registered your custom el-resolver all el-expressions will be evaluated in the way that id-s of component instances will be searched inside the blueprint container. In case you say that you have a bean-property in your faces-config.xml with the value #{myComponent} it will be searched inside the BlueprintContainer.

      这篇关于将蓝图OSGi服务注入JSF/PrimeFaces bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:07