How to load a welding version of osgi version 2 in an SE application

This is really not funny. There is no information on the Internet on how to run the second version (2.1.2.final) of welding-osgi in the application. Instructions for version 1 do not work.

Let the developers be ashamed that they did not provide the necessary samples. I wrote them here .

So, I have an 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 the SE application, I cannot get it through JNDI. I also tried:

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

But in the second line I get

Called: java.lang.IllegalStateException: Singleton is not installed. Is your Thread.currentThread (). getContextClassLoader () installed correctly?

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

EDIT: - , , ( ). ,

+2

Source: https://habr.com/ru/post/1534967/


All Articles