Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Error while calling sling service in jsp in cq5

Sony006
Level 3
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
smacdonald2008
Correct answer by
Level 10
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
smacdonald2008
Correct answer by
Level 10
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