【问题标题】:AEM : getSlingScriptHelper().getService returns nullAEM:getSlingScriptHelper().getService 返回 null
【发布时间】:2018-09-08 08:16:16
【问题描述】:

我正在尝试在我的项目中使用 getSlingScriptHelper().getService,但它一直返回 null。我在其他项目中也这样做过,实现方式类似。我们在项目中使用了 AEM 6.3。我的代码如下:

FOOModel

  public class FOOModel extends WCMUsePojo {

private static final Logger LOGGER = LoggerFactory.getLogger(FOOModel.class);

        private String foo;


        @Override
        public void activate() throws Exception{

            FOOInterface fooInterface = getSlingScriptHelper().getService(FOOInterface.class);   

        LOGGER.info("FOOInterface value is : " + fooInterface);

        }

        public String getFoo() {        
            return foo;
        }

    }

FooInterface

public interface FOOInterface {

    public String getFoo();

}

FOO 实施

@Component(metatype = true, immediate = true, label = "FOO Configuration", description = "OSGi Configuration FOO")
@Service(FOOInterface.class)
public class FOOImpl implements FOOInterface {


    @Property(label = "FOO", description = "FOO to be provided")
    public static final String FOO_URL = "foo.url";


    private String foo;



    @Activate
    public void activate(ComponentContext componentContext){
        Dictionary<?, ?> props = componentContext.getProperties();
        this.foo = PropertiesUtil.toString(props.get(FOO_URL), StringUtils.EMPTY);

    }

    @Override
    public String getSsoUrl() {
        return foo;
    }


}

日志显示“FOOInterface value is : null”。

我尝试过使用类注入方法的 sling 模型,但它也不起作用。

编辑:我发现该服务未激活。附加捆绑包状态的屏幕截图。

【问题讨论】:

    标签: aem sightly


    【解决方案1】:

    很可能您的FOOInterface 服务未激活。您可以查看/system/console/components 以查看其状态。

    可能未正确安装包含该服务的捆绑包。您可以通过/system/console/bundles查看其状态。

    【讨论】:

    • 是的。情况似乎如此。这可能是什么原因?其他项目使用类似的代码运行良好。
    • @Vishal--JAVA--CQ,安装包了吗?是活跃的吗?是否满足依赖关系?尝试安装/激活捆绑包时日志中是否有错误?你需要调试一下,看看发生了什么。
    • bunlde 已安装。它是活跃的。看不到与安装本身相关的任何错误。附上捆绑截图以供参考。任何提示都会有所帮助
    • 尝试在您的服务激活方法中添加一些日志记录并检查错误
    猜你喜欢
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多