Expand my Community achievements bar.

SOLVED

Unsatisfied (reference) Error for a utility class

Avatar

Level 5

I have written a resource type servlet and used a utility class in it.

My core bundle state is active. But, the servlet is showing 'Unsatisfied (reference)' error. 

When I checked for the particular servlet, it is showing me the attached issue.

Please explain what is the exact issue and how to get it resolved.

Capture.PNG

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

We use @reference annotation to inject OSGi service.

 

You can define your Util class as similar to https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/w...

 

Then call the relevant static method using

Utils.methodname("") in your servlet.

View solution in original post

6 Replies

Avatar

Employee Advisor

Is GetUserProfileUtils an OSGi service? How did you call GetUserProfileUtils in your servlet?

Avatar

Level 5

It is not an OSGi service. A plain Util class that I'm calling using @reference annotation.

Avatar

Correct answer by
Employee Advisor

We use @reference annotation to inject OSGi service.

 

You can define your Util class as similar to https://github.com/adobe/aem-core-wcm-components/blob/main/bundles/core/src/main/java/com/adobe/cq/w...

 

Then call the relevant static method using

Utils.methodname("") in your servlet.

Avatar

Community Advisor

Hi Goyal,

 

This normally means that service you referenced from your service is not available in OSGi Service Registry.

 

Regards,

Peter

Avatar

Community Advisor

It might be because the UtilityService that you are trying to use does not exist in the OSGI Apache Felix environment. What's your implementation of the servlet?

Avatar

Community Advisor

You typically wouldn’t use @reference for the Utils class, because it’s reserved for dependency injection, injecting AEM services, as such.

 

If your utils class is created with static methods (as you should), all you would need to do is import the utils class into your project, and call:

 

Utils.getString(“”)

 

if you’d like to be a better backend developer, I would recommend you to download some linting libraries for your IDE like sonarLint. This will dramatically improved your code quality, and also enables learning opportunities as well.