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

ConfigurationManager Reference is null

  • October 16, 2015
  • 13 replies
  • 3532 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

smacdonald2008
Level 10
October 16, 2015

That is a possibility - when you inject a ConfigurationManager - it should not be null. Sham - do you think a ticket should be opened?

Level 2
October 16, 2015

I am sure cfgMgr is null. I added a null check statement to find it out and it came out as null. Do you think I ran into any kind of bug here?

Sham_HC
Level 10
October 16, 2015

Looks right to me. Are you sure cfgMgr is null OR calling configuration cfgMgr.getConfiguration("mycustomservice") is null.