@inject does not work if the bean is not created via hk2

I tried to enter a contract into a contract:

@org.jvnet.hk2.annotations.Contract
public interface CategoryDAO{
}

@org.jvnet.hk2.annotations.Service
public class HibernateCategoryDAO implements CategoryDAO
}

@org.jvnet.hk2.annotations.Service
public class MyCategoryManager implements CategoryManager {

    @javax.inject.Inject
    CategoryDAO categoryDAO;

}

But categoryDAO is null.

I even tried tying it up:

public class ServiceBinder implements Binder {
    @Override
    public void bind(DynamicConfiguration config) {
    config.bind(BuilderHelper.link(HibernateCategoryDAO.class).to(CategoryDAO.class).build());
    }
}

But still, it remains zero.

I initialize MyCategoryManagerwith the Reflections structure as follows:

Set<?> managers = Reflections.getSubTypesOf(CategoryManager.class);
+3
source share
1 answer

, , hk2, ServiceLocator.inject. HibernateCategoryDAO ServiceLocator (, ServiceLocatorUtilities.addClass). , HK2, . , , ServiceLocatorUtilities.addOneConstant, , .

, .

+2

All Articles