1

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;

1 Answer 1

1

@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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.