如何建立服务以及如何在CQ5中激活服务 [英] How to build service and how to active that in CQ5

查看:88
本文介绍了如何建立服务以及如何在CQ5中激活服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天我正在学习OSGI,CQ5.我正在尝试构建一个具有服务的捆绑包(我的第一个代码). 我成功构建了一个捆绑软件,并将其上传到CQ5,并也进行了安装.

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 ?

我也想激活此服务.我怎样才能做到这一点 ?网上有人说要制作jsp.我也这样做,但是没有得到任何回应.帮我解决这个问题.我花了很多时间在此上,进行了大量搜索,但没有任何解决方案.

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.

如何在CQ5,CRXDE(Adobe)中使用我的服务.

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

JSP代码是:-

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

以上代码不起作用.

这些快照是

捆绑包

组件

服务

我的代码为:-

SayHello

package service.expose;

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

public interface SayHello {
    public void sayHelloTest();
}

SayHelloTestServlet //此处的Servlet没有意义.

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");
    }
}

推荐答案

在激活捆绑包后立即使用@Component(immediate=true)实例化您的服务,而不是按需.

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

这篇关于如何建立服务以及如何在CQ5中激活服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆