PatientService component not found

While working on supporting indexing and searching patient allergies, i noticed that org.openmrs.module.allergyapi.api.PatientService is not found when i try accessing it using Context.getService(PatientService.class) or when using getComponent method that looks like;

public static <T> T getComponent(Class<T> clazz) {
	List<T> list = Context.getRegisteredComponents(clazz);
	if (list == null || list.size() == 0)
		throw new RuntimeException("Cannot find component of " + clazz);
	return list.get(0);
}

I also tried passing @SpringBean("allergyService") PatientService patientService into the controller as used in the AllergyUI module which fails with java.lang.IllegalArgumentException: argument type mismatch as at: http://pastebin.com/2X3rc9jg How can i solve this to access the org.openmrs.module.allergyapi.api.PatientService in order to fetch date from the database to be indexed.

This is caused by the fact that you do not have provided for the allergyapi dependency. So your module bundles a copy of this class and gets loaded by your module class loader leading to the type mismatch error because, though the classes have the exact name and package, they are considered different because of being loaded by different class loaders.

A class is identified by name, package and class loader that loaded it.

Does that call for a change in my pom file scope for the allergyapi module from provided to compile? Just not sure if i got your right!

Just add the non existing provided scope

How does that look like? i know only of; compile, provided, runtime and test

provided

That’s what i already have!

I do not see it here:

Thanks @dkayiwa, editing to add the scope that i had missed out by mistake cleared this issue. I hope to get into more troubleshooting of the indexing issues(still not working out) when i get back