The service call should always be made using the interface name which you have registered. So if you see you have registered the service as
@scr.service interface="testService" // Please define the correct name as in your case its TestService, so make it @scr.service interface="TestService"
Now you can call your service
SlingHttpServletRequest r = (SlingHttpServletRequest)request;
TestService testService = (TestService) sling.getService(TestService.class); // instead using implementor.
I hope it helps you. Let me know for more information.
Thanks for your information. It was problem with my pom.xml It started to work after changing my POM.xml
I am not able to get sling service for TestServiceImpl. But I am only able to create TestService which is my interface. I need to get reference for TestServiceImpl class not for TestService interface. Please help me to make it.
i have created TestServiceImpl and TestService class for testing whether my bubdle is crating all the folder structure or not.
But my requirement is like assume class A has some methods like getMenuLink, setMenuLink.. And In class B i am calling some methods in class A and doing some manipulation in createLink method.
Here class B does not have any interface. Not implementing any interface. But I need to get class B refererence via sling.getService.
I know that if we are using maven SCR plugin..we need to have @component, @service. And All java classes are not services. Will it work if I add activate, deactivate method in class B?
Could you please tell me how to proceed next?
Answers to your both questions
1. The TestService instance will have reference to TestServiceImpl only and you can access all its method through same instance.
2. Not sure why you want to use sling.getService to retrive reference of any class instead of directly creating the instance in your target class (basic java approach - as both classes are your custom so you can design that way)
If you still have such requirement then create B class as service and register it. so like this create B as interface and BImpl as implementor (same as TestServiceImpl) and then
B b=(B)sling.getService(B.class); // will return you instance reference in your A class
Let me know for more information.