Error while calling sling service in jsp in cq5 | Community
Skip to main content
Level 3
October 16, 2015
Solved

Error while calling sling service in jsp in cq5

  • October 16, 2015
  • 1 reply
  • 2742 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

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. 

1 reply

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

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.