How to build service and how to active that in CQ5

会有一股神秘感。 提交于 2019-12-13 19:58:54

问题


I am learning OSGI, CQ5 these days. I am trying to build a bundle that have service (My first code). I successfully build a bundle and upload that bundle on CQ5, and install that also.

But component shows registered only, not active. Why ?

I also want to activate this service. How can I do this ? Someone on net said to make jsp. I also do that, but didn't get any response. Help me from this problem. I spent lot of time on this, lot of searching, but I didn't get any solution.

How can I use my service in CQ5, CRXDE(Adobe).

JSP code are :-

<% var service =   sling.getService(Packages.mh.osgitest.SayHello); %> 
<%= service.sayHelloTest() %>

Above code is not working.

The snapshots of these are

Bundle

component

service

My codes are as :-

SayHello

package service.expose;

import org.apache.felix.scr.annotations.Service;

public interface SayHello {
    public void sayHelloTest();
}

SayHelloTestServlet // Servlet have no sense here.

package service.expose;

import java.io.IOException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Service;


@Component
@Service(value = SayHello.class)
public class SayHelloTestServlet implements SayHello {

    public void sayHelloTest() {
        System.out.println("Testing Say Hello");
    }

    @Activate
    protected void activate() {
        System.out.println("service started");
    }


    @Deactivate
    protected void deactivate() {
        System.out.println("service stopped");
    }
}

回答1:


Use @Component(immediate=true) to instantiate your service as soon as the bundle is activated as opposed to on-demand.



来源:https://stackoverflow.com/questions/14627447/how-to-build-service-and-how-to-active-that-in-cq5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!