Search code examples
servicereferencedependency-injectionadobeaem

Adobe CQ: Injecting services via @Reference returns null


I'm trying to inject a service into the component via @Reference annotation in Adobe CQ5, but after deployment it always returns null to me instead of service instance.

@Component(immediate = true)
@Service(value = GoodbyeWorldService.class)  
public class GoodbyeWorldService {
    @Reference
    protected Scheduler scheduler;
    private final static Logger LOGGER = LoggerFactory.getLogger(GoodbyeWorldService.class);

    public void get() {
       LOGGER.info("Scheduler is " + this.scheduler);
   } 
}

The JSP:

<%@ include file="/apps/cqblueprints-example/components/global.jspx" %>    
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>    
<jsp:useBean id="goodbye" class="com.cqblueprints.example.services.GoodbyeWorldService" scope="page" />      
<% goodbye.get(); %>    

In the log I get:

2014-04-02 12:24:09.999 INFO [com.cqblueprints.example.services.GoodbyeWorldService] Scheduler is null

I've tested other simple print methods from this bean. They are working like charm.

What am I missing?


Solution

  • The problem is solved! I have just updated the version of maven-scr-plugin from 1.7.4 to 1.9.0 and it started to work! Now I am retrieving my instances via @Reference annotations and I see my service in "Services" and "Components" tabs in Felix OSGi Console. Thanks to all who replied here!