Hi I am trying to consume QueryBuilder service in other OSGI bundle in CQ5. But the queryBuilder object is returning null value. Can i get suggestion to consume it properly?
@Reference
private QueryBuilder queryBuilder;
@Reference annotation will work only if you are specifying it in an OSGI Service. Can you confirm that its a class with @Service and @Component annotation on it?
//This is a component so it can provide or consume services
@Component
@Service
public class SearchServiceImpl implements SearchService {
/** Default log. */
protected final Logger log = LoggerFactory.getLogger(this.getClass());
private Session session;
//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;
@Reference
private QueryBuilder builder;
//---- Rest of your code
}
Refer to the implementation here.
Also if you are using @Component annotation on your class, you could goto /system/console/components and search for your class and look at the details, it will tell you if the dependencies are getting resolved and state of service.