@reference returns null. | Community
Skip to main content
Nandujee
Level 3
October 16, 2015
Solved

@reference returns null.

  • October 16, 2015
  • 2 replies
  • 1742 views

Hello,

I have created service say XX. I tried to access that service XX in other Service YY. 

When I try to use the XX like 

@Reference XX xx in YY service

I got a null value.

Code:

@Component(immediate = true)

@Service(value = XX.class)
public class XX{
//some methods
}

@Component(immediate =true)
@Service(value=ZZ.class)
public class YY implements ZZ{
    @Reference
    XX xx;

public SB  aa(String ss) {
        LOG.info(xx);//Null

}

When I access my service in my servlet, It is working fine..

like 

 

@Component(immediate = true)
@Service(javax.servlet.Filter.class)
public class FilterManager implements Filter {

    @Reference
    XX xx;

    LOG.info(xx);//I can get an object here

}

Kindly guide me, Is it possible to access service inside other service? 

Note:

In Felix console, can I see the service is active for both XX, YY.

Thanks

Nanda

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

Yes - as long as the service is part of the AEM Service container - you can inject it into another service. See this article as an example. Notice that we are injecting a DataSourcePool into a custom AEM service:

http://helpx.adobe.com/experience-manager/using/datasourcepool.html

2 replies

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

Yes - as long as the service is part of the AEM Service container - you can inject it into another service. See this article as an example. Notice that we are injecting a DataSourcePool into a custom AEM service:

http://helpx.adobe.com/experience-manager/using/datasourcepool.html

Level 4
September 8, 2016

Nandujee wrote...

Hello,

I have created service say XX. I tried to access that service XX in other Service YY. 

When I try to use the XX like 

@Reference XX xx in YY service

I got a null value.

Code:

@Component(immediate = true)

@Service(value = XX.class)
public class XX{
//some methods
}

@Component(immediate =true)
@Service(value=ZZ.class)
public class YY implements ZZ{
    @Reference
    XX xx;

public SB  aa(String ss) {
        LOG.info(xx);//Null

}

When I access my service in my servlet, It is working fine..

like 

 

@Component(immediate = true)
@Service(javax.servlet.Filter.class)
public class FilterManager implements Filter {

    @Reference
    XX xx;

    LOG.info(xx);//I can get an object here

}

Kindly guide me, Is it possible to access service inside other service? 

Note:

In Felix console, can I see the service is active for both XX, YY.

Thanks

Nanda

 

 


Hi ,

I am also facing the same issue, could you please let us know how did you resolve this.

In our case we have two different bundles and trying to access the service as

@Reference

ServiceXyz xyz;

But its giving null.

Regards

Ankur