Sling Annotations
Which annotation is prefered to access the Service inside another service and why? @3214626 or @OSGiService.
Thanks
Which annotation is prefered to access the Service inside another service and why? @3214626 or @OSGiService.
Thanks
Hi @madhur-madan,
On OSGi service level you should use Reference annotation. So this will be option you should use in case you want to get reference of other OSGi service inside another.
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component
public class YourService {
@Reference
private OtherService otherService;
}
OSGiService annotation is dedicated for Sling Model it will not work inside OSGi service/component. You can use it, in case you would like to inject OSGi Service into your Sling Model.
See also below links:
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.