*** The wcm.io Project is closing down this JIRA Instance in favor of GitHub issues. *** Please use the corresponding GitHub projects to report issues - or the mailing list for general discussion.

Issues

Select view

Select search mode

 

Cannot register service with ModelFactory reference in AemContext

Fixed

Description

I'm trying to test one of my services, which uses OSGi annotation @Reference to inject org.apache.sling.models.factory.ModelFactory.

I'm using AemMocks 2.3.2 (also tested with 2.2.12) and get following error on attempt of service registration:

aemContext.registerInjectActivateService(new MyServiceImpl());

org.apache.sling.testing.mock.osgi.ReferenceViolationException: Multiple matches found for unary reference 'modelFactory' for class ../MyServiceImpl.class

Debugger says that there are 110 matching services of ModelFactory are registered, so it cannot pick any particular one.

It works fine with any other References we inject in our project.

Details

Assignee

Reporter

Components

Fix versions

Priority

Created October 17, 2018 at 12:33 PM
Updated August 21, 2019 at 8:03 AM
Resolved October 19, 2018 at 2:28 PM

Activity

Show:

Stefan SeifertMarch 4, 2019 at 5:46 PM

thanks, i could reproduce the problem. the source of the problem was different than described in this ticket, though - they really where multiple references present and osgi-mock did throw an exception because of this. this was wrong, and is fixed in SLING-8303 - in OSGi Mock 2.4.8 / AEM Mock 2.4.2

Stefan SeifertFebruary 19, 2019 at 11:43 AM

do you have a test project available to reproduce the problem?
alternatively, can you attach the output of mvn dependency:tree of your project?

David GonzalezFebruary 18, 2019 at 5:23 PM

@Stefan Seifert,

I moved the `osgi-mock` and `aem-mock` dependencies to the top of my bundle project's dependencies to ensure those versions are used, but to no avail.

I don't see anything else that would override these dependencies..? (I had Sling's `sling-mock` but removed that). I am using the AEM 6.3.1 UberJar but I wouldn't imagine any of these should/would be in that?

Any thoughts on where this might be overridden?

I noticed when I move the `sling-mock` dependency above the UberJar,
`modelFactory.getModelFromWrappedRequest(...)` could not be resolved, i'm not sure if that is a clue.

Stefan SeifertFebruary 18, 2019 at 9:14 AM

the issue was resolved in the underlying osgi mock 2.4.4 - can you cross-check that you have not overridden the osgi mock dependency in your project and osgi mock 2.4.4 or higher is in use?

Loading...