Depending on openmrs-core Services

Following info from this doc, I have still failed to depend on openmrs-core Services. For my module, this line throws the error below.

ERROR - Context.getServiceContext(258) |2018-05-26 23:08:23,559| serviceContext is null.  Creating new ServiceContext()

Could I be missing something? Here is my moduleApplicationContext.xml.
cc: @ssmusoke , @dkayiwa, @ivange94 etc

Change your base class to BaseModuleContextSensitiveTest

Thanks @dkayiwa .
On extending BaseModuleContextSensitiveTest ,

//This works fine
@Autowired
@Qualifier("patientService")
 PatientService service;

//This still fails out
PatientService service = Context.getPatientService();

Why is this happening like that?

Do that in a method instead of at the class level.

Well that has worked for me. thanks @dkayiwa
But hey !
Calling Context.getService(PatientResourceService.class) throws this exception. Here is my moduleApplicationContext.xml. Could I be missing something?
cc: @ssmusoke

The problem could be this, you’re defining 2 value and ref tags and am not 100% sure if spring can automatically know which value tag is related to a given ref tag, can you try separating them? Basically create 2 child beans where the parent is serviceContext i.e one for each service

Thanks @wyclif for the reply. But did you mean something like this? If so, I don’t know why the error persists :frowning:

Ooohh thanks @wyclif and @dkayiwa . It worked at last :smile:

Nice! @samuel34 sometimes it’s good to mention the change you made to get it to work so that others who run into the same issue in the future and come across this post can know the fix.

After doing the above, I had to invoke “Context.getService(MyService.class)” at a method level not field.

@Before
public void setup() { 
   MyService service = Context.getService(MyService.class);
}