Aem 如何获得;吊索模型的委托模式”;工作

Aem 如何获得;吊索模型的委托模式”;工作,aem,sling-models,Aem,Sling Models,我正在尝试为AEM核心组件创建一个代理组件,该组件使用定制的吊索模型,将部分功能委托给核心组件的吊索模型 我遵循的是来自的示例,但它导致java.lang.IllegalArgumentException:无法设置com.example.core.models.Title字段 安装程序 AEM版本6.4.4 core.wcm.components.content版本2.4.0 来源 /apps/myproject/components/pageHeadline/.content.xml

我正在尝试为AEM核心组件创建一个代理组件,该组件使用定制的吊索模型,将部分功能委托给核心组件的吊索模型

我遵循的是来自的示例,但它导致
java.lang.IllegalArgumentException:无法设置com.example.core.models.Title字段

安装程序
  • AEM版本6.4.4
  • core.wcm.components.content版本2.4.0
来源 /apps/myproject/components/pageHeadline/.content.xml


com.example.core.models.PageHeadline

package com.example.core.models;
导入com.adobe.cq.wcm.core.components.models.Title;
导入com.day.cq.wcm.api.Page;
导入org.apache.sling.api.SlingHttpServletRequest;
导入org.apache.sling.models.annotations.Model;
导入org.apache.sling.models.annotations.Via;
导入org.apache.sling.models.annotations.injectorspecific.ScriptVariable;
导入org.apache.sling.models.annotations.injectorspecific.Self;
导入org.apache.sling.models.annotations.via.ResourceSuperType;
@模型(adaptebles=SlingHttpServletRequest.class,adapters=Title.class,resourceType=“myproject/components/pageHeadline”)
公共类PageHeadline实现标题{
@脚本变量
私有页面当前页面;
@Self@Via(type=ResourceSuperType.class)
私人产权代表;
@凌驾
公共字符串getText(){
返回currentPage.getTitle();
}
@凌驾
公共字符串getType(){
返回delegate.getType();
}
}
结果
我也遇到了同样的问题,委托模式不起作用,特别是,如果我使用
@Optional
,则注入的属性为null,或者如果忽略
@Optional
,则插入的堆栈跟踪与发布的堆栈跟踪相同

我遇到的问题是,我们使用的是以下
嵌入依赖项
代码:

<Embed-Dependency>
  *;scope=compile|runtime
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>

你能同时添加htl代码吗?到目前为止,你的代码看起来还不错。与您链接的Github页面相比,没有任何更改。我可以想象,在AEM中没有部署核心组件,但这实际上只是一个偶然的机会,因为那时我会预期出现某种“缺少类定义”的异常。委托模式是在Sling API 1.3.4/1.4(API/impl)中添加的。我不确定你的AEM的具体版本。你能确认你至少使用了那个版本吗?(检查felix bundle控制台)如上所述,特定AEM版本为6.4.4。核心组件已部署且工作正常。没有定制的HTL代码,因为它使用的是sling:resourceSuperType=“core/wcm/components/title/v2/title。谢谢你的提示!我将试用一下,看看效果如何。
<Embed-Dependency>
  *;scope=compile|runtime
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>
  *;scope=compile|runtime;artifactId=!core.wcm.components.core
</Embed-Dependency>