Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
567 views
in Technique[技术] by (71.8m points)

java - How to bootstrap weld-osgi version 2 in SE application

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...