第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 aem groovy 控制臺中獲取服務(wù)?

如何在 aem groovy 控制臺中獲取服務(wù)?

哈士奇WWW 2023-06-14 15:43:14
我需要創(chuàng)建一個 Java 服務(wù),并從 aem groovy 控制臺請求該服務(wù)。我創(chuàng)建了一個作為 Java 類的服務(wù),構(gòu)建并部署到本地 aem 實例,當(dāng)我嘗試使用 getService 函數(shù)詢問它時,它不起作用,并且出現(xiàn)錯誤。我正在嘗試以這種方式獲得服務(wù):def jcrService = getService(TestService.class)out.println(jcrService.test())并以這種方式:import example.core.services.TestService;TestService testService = new TestService();out.println(testService.test())當(dāng)我導(dǎo)入我的服務(wù)類時,它正在工作。但是當(dāng)我實現(xiàn)與 jcr.Session 和 jcr.Nodes 一起工作的基本接口時,它不起作用。
查看完整描述

1 回答

?
楊__羊羊

TA貢獻(xiàn)1943條經(jīng)驗 獲得超7個贊

提供 FQCN(完全合格的類名)對我來說很好。請找到以下示例。


常規(guī)腳本:


def testService = getService("com.project.services.TestService")


println "title is: " + testService.getTitle();

print "url is: " + testService.getUrl();

結(jié)果:


title is: Test Service Title

url is: http://localhost:4502

測試服務(wù):


package com.project.services;


public interface TestService {

    public String getTitle();

    public String getUrl();

}

測試服務(wù)實現(xiàn)


package com.project.services.impl;


import org.osgi.service.component.annotations.Activate;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.metatype.annotations.Designate;


import com.project.services.configuration.TestServiceConfig;

import com.project.services.TestService;


@Component(service = TestService.class, name = "TestService", immediate = true)

@Designate(ocd = TestServiceConfig.class)

public class TestServiceImpl implements TestService {


    private String url;


    @Override

    public String getTitle() {

        return "Test Service Title";

    }


    @Override

    public String getUrl() {

        return url;

    }


    @Activate

    protected void activate(TestServiceConfig testServiceConfig) {

        url = testServiceConfig.url();

    }


}


測試服務(wù)配置


package com.project.services.configuration;


import org.osgi.service.metatype.annotations.AttributeDefinition;

import org.osgi.service.metatype.annotations.ObjectClassDefinition;


@ObjectClassDefinition(name = "Test Service Config", description = "Test Service Configuration.")

public @interface TestServiceConfig {


    @AttributeDefinition(name = "url", description = "Provide URL for localhost")

    String url() default "http://localhost:4502";

}


查看完整回答
反對 回復(fù) 2023-06-14
  • 1 回答
  • 0 關(guān)注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號