如何在SE应用程序中引导焊接osgi版本2 [英] How to bootstrap weld-osgi version 2 in SE application

查看:93
本文介绍了如何在SE应用程序中引导焊接osgi版本2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的不好笑在互联网中没有信息如何在se应用程序中运行焊接osgi第二版本(2.1.2.final)。 ver 1的说明不行。



让开发人员感到羞愧,他们没有提供必要的样本。我写了他们 here



所以,我有和OSGi激活器,我想从它获取豆。在GF4中,我使用这个:

  private BeanManager getBeanManager()throws NamingException 
{
try {
InitialContext initialContext = new InitialContext();
return(BeanManager)initialContext.lookup(java:comp / BeanManager);
}
catch(NamingException e){
System.out.println(Can not get BeanManager through JNDI);
返回null;
}
}

但在SE应用程序中,我无法通过JNDI。
我也尝试过:

 焊缝= new Weld(); 
BeanManager beanManager = weld.getBeanManager();

但是在第二行我得到


导致:java.lang.IllegalStateException:未设置Singleton。
你的Thread.currentThread()。getContextClassLoader()正确设置?


如何从激活器开始使用CDI?我的错误是什么?



编辑:
我做了什么 - 我发现使用它的两个程序的两个源代码,但实际上并不容易在他们的基地(至少对我来说)。第一个是这里,第二个是 here

解决方案

焊接osgi子项目不再支持焊接2.相反,使用Pax CDI项目提供与OSGi的集成。



可以在这里找到Pax CDI文档: https://ops4j1.jira.com/wiki/display/PAXCDI/Pax+CDI



其他信息可在:
- http://karaf.apache.org/manual/latest/users-guide/cdi.html
- https://github.com /weld/core/blob/master/examples/osgi/README.md


It's really not funny. There is no information in internet how to run weld-osgi second version (2.1.2.final) in se app. Instructions for ver 1 don't work.

Let the developers be ashamed that they didn't provide necessary samples. I wrote them here.

So, I have and OSGi activator and I want to get beans from it. In GF4 I used this:

private BeanManager getBeanManager() throws NamingException
{
  try{
   InitialContext initialContext = new InitialContext();
            return (BeanManager)  initialContext.lookup("java:comp/BeanManager");
   }
  catch (NamingException e) {
            System.out.println("Couldn't get BeanManager through JNDI");
            return null;
   }
}

But in SE application I can't get it through JNDI. Also I tried:

Weld weld=new Weld();
BeanManager beanManager=weld.getBeanManager();

But at the second line I get

Caused by: java.lang.IllegalStateException: Singleton is not set. Is your Thread.currentThread().getContextClassLoader() set correctly?

How can I use CDI starting from activator? What is my mistake?

EDIT: What I did - I found two source code of two programs that use it, but it's really no so easy to write on their base (at least for me). The first is here and the second is here

解决方案

The weld-osgi subproject is not supported anymore with Weld 2. Instead, integration with OSGi is provided using the Pax CDI project.

Pax CDI documentation can be found here: https://ops4j1.jira.com/wiki/display/PAXCDI/Pax+CDI

Additional information can be found at: - http://karaf.apache.org/manual/latest/users-guide/cdi.html - https://github.com/weld/core/blob/master/examples/osgi/README.md

这篇关于如何在SE应用程序中引导焊接osgi版本2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆