CDI inside OSGI - it does not see bean

I have two OSGI packages:
The first contains: service, servlet, pojo The
second contains: consumer (services).

FACTS:
A) I order the service (package 1) to the consumer (package 2) via CDI (@OSGiService) - everything is in order.
B) I insert pojo into the servlet via CDI (manually using beanManager.getBeans, beanManager.resolve) - everything is fine.
C) I insert pojo for service via CDI (manually using beanManager.getBeans, beanManager.resolve) - Error - cannot find bean.

The reason I use manual injection is because I couldn't get it to work with @Inject and started a google search. And I found this

CDI allows injection into non-component classes, but CDI still needs to be instantiated. Your activator is created by OSGi and CDI is not able to connect to this process. You can programmatically master the CDI injection manager and query from it instead of using @Inject in your main class.

I think that (C) should work because the instance is created via CDI, but that is not the case. Where is the mistake?

EDIT: Glassfish4, welding, apache felix

The source code of 3 packages (1 package with an interface) can be downloaded here . There are two servlets:
The first one can be accessed / testme 1 / NewServlet1 (bundle 1)
The second one can be accessed / testme 2 / NewServlet2 (package 2)

+4

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


All Articles