Is it possible to inject a @reference object in a service with normal initialization?
Hi all,
Is it possible to initialize the object in class with @reference in a service with normal java initialization?
Example:
This is the class
public class AEMUtilImpl implements AEMUtil {
@Reference
private ResourceResolverFactory resourceFactory;
@Reference
private SlingRepository slingRepository;
}
If I'm initializing this class in another class (like a servlet) like this:
AEMUtil aem = new AEMUtilImpl();
resourceFactory and slingRepository is always null.
If I initialize like this in a servlet
@Reference
AEMUtil aem;
resourceFactory and slingRepository do get initialized and works properly.
What is the reason behind this? Is there anyway we can initialize by using the first method?