Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

osgi service giving nullpointer exception


Level 2

i am trying with osgi service in cq5.5 but throwing nullpointerexception

 Please find below code



import javax.jcr.Node;
import javax.jcr.RepositoryException;

public interface HelloService {
    public String sayHello();
    public String getReversedNodePath(Node node)  throws RepositoryException;
    public String getRepository();
    public void log(String text);





import javax.jcr.Node;
import javax.jcr.RepositoryException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class HelloServiceImpl implements HelloService{

    private SlingRepository repository;
    private static final Logger log = LoggerFactory.getLogger(HelloServiceImpl.class);
    public String sayHello() {
        return ("Hello World!!");
    public String getReversedNodePath(Node node) throws RepositoryException {
        return new StringBuffer(node.getPath()).reverse().toString();

    public String getRepository() {        
        return repository.getDescriptor(SlingRepository.REP_NAME_DESC);
    protected void bindRepository(SlingRepository repository) {
        this.repository = repository;
    protected void unbindRepository(SlingRepository repository) {
        this.repository = null;

    public void log(String text) {




<?xml version="1.0" encoding="UTF-8"?>
<components xmlns:scr="">
    <scr:component enabled="true" immediate="true" name="">
        <scr:implementation class=""/>
        <scr:service servicefactory="false">
            <scr:provide interface=""/>
        <scr:property name="service.description" value="Say hello sample service"/>
        <scr:property name="service.vendor" value="Day"/>
        <scr:property name="" value=""/>
        <scr:reference name="repository" interface="" cardinality="1..1" policy="static" bind="bindRepository" unbind="unbindRepository"/>




<%@include file="/libs/foundation/global.jsp" %>
<div class="container_16">
    <div class="grid_16">
        <div> breadcrumb </div>
        <div> title </div>
    <div class="grid_12 body_container">
        <cq:include path="par" resourceType="foundation/components/parsys" />
    <div class="grid_4 right_container">
        <div> newslist </div>
        <div> rightpar </div>
    <div class="clear"></div>

    <% service =   sling.getService(;%>

    <% if(service !=  null ){ %>

    <%= service.sayHello() %>



but sling.getService(; (service)returning null


please let me know what could be wrong here


please find jar as an attachment

0 Replies