0
votes

I am trying to register a simple service in OSGi but, its not visible in the felix console once i write @Reference . Below is my service.

@Component(metatype = true , immediate = true)
@Service(value = LoginAccessService.class)
@Properties({
        @Property(name = "service.vendor", value = "AEM.Training"),
        @Property(name = "service.description", value = "Login Access Testing")
})
public class LoginAccessImpl implements LoginAccessService {

    private static final Logger logger = LoggerFactory.getLogger(LoginAccessImpl.class);
    @Reference
    protected AbstractSlingRepository2 repository;

    @Override
    public Node createNode(String path) {

        return null;
    }
}

In Case if I write

    @Reference
    protected SlingRepository repository;

Its reflect in felix. Any Idea how this happens.

1
Is your project bundle in active state when you build the code with AbstractSlingRepository2 ? - Sharath Madappa
Probably there is no OSGi service available in the OSGi container that is registered with the AbstractSlingRepository2 type. - Balazs Zsoldos
My Bundle is active & dependencies are resolved. org.apache.sling.jcr.base.AbstractSlingRepository2 - Vivek Dhiman
Check the OSGi console. First if the bundle is active, then if your component is active. If not, check the details. In the bundle you would see unresolvable dependencies and in the component unsatisfied references. - Thomas
Yes component is in unsatisfied state ["Unsatisfied","Service Name: org.apache.sling.jcr.base.AbstractSlingRepository2","Multiple: single","Optional: mandatory","Policy: static","No Services bound"] . But why so - Vivek Dhiman

1 Answers

1
votes
  1. Only the interface can be referenced since the @Service can be registered only by its interface(s). And the AbstractSlingRepository2 is an abstract class, not interface.
  2. The AbstractSlingRepository2 is available only in Sling v7 which is used in AEM (CQ) since v6.0

So using

@Reference
protected SlingRepository repository;

is a proper way to get the repository.