How to bootstrap weld-osgi version 2 in SE application

混江龙づ霸主 提交于 2019-11-28 09:58:05

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/22878449/how-to-bootstrap-weld-osgi-version-2-in-se-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!