I usually access my Services via constructor injection, but I have a use case where I would rather like to inject it via the ComponentAccessor (I know it should be used rarely).
My Service Interface and implementation look like this:
@Named
public class MyServiceImpl implements MyService{
@ComponentImport
private final ActiveObjects ao;
@Inject
public MyServiceImpl(ActiveObjects ao) {
this.ao = checkNotNull(ao);
}
...
}
public interface MyService {
...
}
And I’m trying to inject it like this, but always get a null object:
ConfigService configService= ComponentAccessor.getOSGiComponentInstanceOfType(MyService.class);
With constructer injection it works though. Can anyone give me a hint?