Unsatisfied (reference) Error for a utility class | Community
Skip to main content
Level 4
Feb 7, 2023 12:02 PM UTC
Solved

Unsatisfied (reference) Error for a utility class

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.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
DEBAL_DAS
DEBAL_DASAccepted solution
New Participant
Feb 8, 2023 9:15 AM UTC

We use @3214626 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/wcm/core/components/internal/Utils.java

 

Then call the relevant static method using

Utils.methodname("") in your servlet.

6 replies

BrianKasingli
New Participant
Feb 8, 2023 5:31 AM UTC

You typically wouldn’t use @3214626 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. 

Translate
BrianKasingli
New Participant
Feb 8, 2023 2:31 AM UTC

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?

Translate
Peter_Puzanovs
New Participant
Feb 7, 2023 12:56 PM UTC

Hi Goyal,

 

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

 

Regards,

Peter

Translate
DEBAL_DAS
New Participant
Feb 7, 2023 12:17 PM UTC

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

Translate
Level 4
Feb 8, 2023 3:07 AM UTC

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

Translate
DEBAL_DAS
DEBAL_DASAccepted solution
New Participant
Feb 8, 2023 9:15 AM UTC

We use @3214626 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/wcm/core/components/internal/Utils.java

 

Then call the relevant static method using

Utils.methodname("") in your servlet.

Translate