ConfigurationManager Reference is null | Community
Skip to main content
Level 2
October 16, 2015
Solved

ConfigurationManager Reference is null

  • October 16, 2015
  • 13 replies
  • 3519 views
import com.day.cq.wcm.webservicesupport.Configuration; import com.day.cq.wcm.webservicesupport.ConfigurationManager; @Component(immediate=true) public class Videos { private final Logger log = Logger.getLogger(Videos.class); private Configuration configuration; @Reference private ConfigurationManager cfgMgr; public void connectToService() { configuration = cfgMgr.getConfiguration("mycustomservice"); } }

 

cfgMgr is null. I wonder why is a reference variable null anyway. Are there any other methods to get it? Any help is appreciated. Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by JustinEd3

The problem doesn't have anything to do with this class. It has to do with how you are accessing this class or really the instance. You are creating a new instance of this class. Instead, you should use the instance created by DS.

You should not use getServiceReference() in a DS component except for very specific needs (which this is definitely not an example of).

13 replies

Adobe Employee
October 16, 2015

bhavani IKKURTHI wrote...

justin_at_adobe wrote...

The problem doesn't have anything to do with this class. It has to do with how you are accessing this class or really the instance. You are creating a new instance of this class. Instead, you should use the instance created by DS.

You should not use getServiceReference() in a DS component except for very specific needs (which this is definitely not an example of).

 

Well, if I access the DS instance of the class using @Reference annotation it returns null.

 

How are you getting the DS instance? Through the ScrService ?

Level 2
October 16, 2015

justin_at_adobe wrote...


bhavani IKKURTHI wrote...

justin_at_adobe wrote...

The problem doesn't have anything to do with this class. It has to do with how you are accessing this class or really the instance. You are creating a new instance of this class. Instead, you should use the instance created by DS.

You should not use getServiceReference() in a DS component except for very specific needs (which this is definitely not an example of).

 

Well, if I access the DS instance of the class using @Reference annotation it returns null.

 

How are you getting the DS instance? Through the ScrService ?

 

I am not following you. DS instance of what? ConfigurationManager class?

Adobe Employee
October 16, 2015

bhavani IKKURTHI wrote...

justin_at_adobe wrote...


bhavani IKKURTHI wrote...

justin_at_adobe wrote...

The problem doesn't have anything to do with this class. It has to do with how you are accessing this class or really the instance. You are creating a new instance of this class. Instead, you should use the instance created by DS.

You should not use getServiceReference() in a DS component except for very specific needs (which this is definitely not an example of).

 

Well, if I access the DS instance of the class using @Reference annotation it returns null.

 

How are you getting the DS instance? Through the ScrService ?

 

I am not following you. DS instance of what? ConfigurationManager class?

 

No. The Videos class.

You are doing this:

Videos videos = new Videos(); videos.connectToService()

This is a different instance of the Videos class than the one which is managed by the Declaritive Services (DS) runtime. Only the managed instance will have the fields injected. Any other instance of this class will not.