Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Error while calling sling service in jsp in cq5

Avatar

Level 3

Hi,

When i want to call my created service in one of my component, the below error i am getting.

An error occurred at line: 20 in the jsp file: /apps/accordian/content/components/servicecalling/servicecalling.jsp
com.app.services.ValuePassServiceImpl cannot be resolved to a type
17:
18:
19: <%
20: com.app.services.ValuePassService vps=sling.getService(com.app.services.ValuePassServiceImpl.class);
21:
22:     %>

 

My component jsp as follows..

<%@include file="/libs/foundation/global.jsp"%>

<%@page session="false" %>
<%@ page import="org.apache.sling.commons.json.io.*,org.w3c.dom.*,com.app.services.*"%>
Service calling Comp
<%
   com.app.services.ValuePassService vps=sling.getService(com.app.services.ValuePassServiceImpl.class);

%>

 

Can anybody help me to find the reason.

My service is not able to active state. It is in registered state, is this the cause?

If yes how to make it active?

Thanks,

Sony C

1 Accepted Solution

Avatar

Correct answer by
Level 10

You are experiencing this issue because in your sling call -- you are referencing the implementation class -- not the interface. You have:

<%
20: com.app.services.ValuePassService vps=sling.getService(com.app.services.ValuePassServiceImpl.class);
21:
22:     %>

It should be

<%
20: com.app.services.ValuePassService vps=sling.getService(com.app.services.ValuePassService.class);
21:
22:     %>

For anyone else following this thread and want to learn how to create a custom AEM service and call it from a JSP using sling.getService()-- see this community article: http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html.

Also - make sure that the OSGi bundle that contains the service is in an Active state - as shown in this article. 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

You are experiencing this issue because in your sling call -- you are referencing the implementation class -- not the interface. You have:

<%
20: com.app.services.ValuePassService vps=sling.getService(com.app.services.ValuePassServiceImpl.class);
21:
22:     %>

It should be

<%
20: com.app.services.ValuePassService vps=sling.getService(com.app.services.ValuePassService.class);
21:
22:     %>

For anyone else following this thread and want to learn how to create a custom AEM service and call it from a JSP using sling.getService()-- see this community article: http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html.

Also - make sure that the OSGi bundle that contains the service is in an Active state - as shown in this article.