Multiple implementation of a Sling Service
Hi experts,
I came across a scenario through one of my colleagues. I believe you guys can help me find solution for this issue.
What happens if there are multiple implementations for a service interface?
For instance consider the following interface,
public interface CheckService { public String getDetails(); }and the implementations classes as follows.
Implementation1:
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; @Component(enabled=true,immediate=true) @Service(value=CheckService.class) @Property(name="id",value="check1") public class CheckServiceImpl1 implements CheckService { @Override public String getDetails() { return "I am from Impl 1 - One"; } }Implementation2:
import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Service; @Component(enabled=true,immediate=true) @Service(value=CheckService.class) @Property(name="id",value="check2") public class CheckServiceImpl2 implements CheckService { @Override public String getDetails() { return "I am from Impl 2 - Two"; } }When i tried to invoke the service from JSP, the output i got is "I am from Impl 1 - One". I am not sure why implementation class2 didnt get invoked. It would be really helpful if you experts could provide some thoughts.
Thanks,
Jai.