7 Replies Latest reply on Aug 7, 2017 3:17 AM by vitis90

    Is it possible to inject a @reference object in a service with normal initialization?

    vitis90 Level 1

      Hi all,


      Is it possible to initialize the object in class with @reference in a service with normal java initialization?



      This is the class

      public class AEMUtilImpl implements AEMUtil {  


          private ResourceResolverFactory resourceFactory;



          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



      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?