我正在使用非常基本的Sling Model类,它根本不起作用。这是类:AEM 6.3 - 吊带模型不起作用
package com.aem.sites.models.test;
import org.apache.sling.models.annotations.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import org.apache.sling.api.resource.Resource;
@Model(adaptables=Resource.class)
public class TestModel {
final static Logger logger = LoggerFactory.getLogger(TestModel.class);
private String email;
@PostConstruct
public void init() {
logger.info("=====================================================================inside init method");
email = "[email protected]";
}
public String getEmail() {
return email;
}
}
我也包括在这样的部分包:
我也找过吊带Model类在这里http://localhost:4502/system/console/status-adapters
,并发现它的像这样的条目:
Adaptable: org.apache.sling.api.resource.Resource
Providing Bundle: org.apache.sling.models.impl
Available Adapters:
* com.aem.sites.models.test.TestModel
更令人惊讶的是包com.aem.sites.models.header中的Sling Model类被正确调用。
我不知道什么是错的。
在此先感谢
共享HTL类:
<sly data-sly-use.bannerObj=com.aem.sites.models.test.TestModel">
<section id="banner"
style="background-image: url('/content/dam/aem-site/banner.jpg')">
<div class="inner">
<h2>Today's temperature is</h2>
<p>
${bannerObj.email}
</p>
<ul class="actions">
<li><a href="#content" class="button big special">Sign Up</a></li>
<li><a href="#elements" class="button big alt">Learn More</a></li>
</ul>
</div>
</section>
</sly>
如果不工作,我的意思是什么也没有发生。 error.log文件中没有出现错误或任何日志。
你是什么意思不工作?你在哪里使用吊索模型?你能分享这个html吗? –
用我所需的信息更新了我的文章。 – user972418
可以在AEM中加载的类是旧版本吗?尝试彻底卸载软件包,删除软件包,然后确保软件包已被删除,并且模型未显示在状态适配器中。然后重新部署您的项目。也可以尝试仅在吊索模型包中使用com.aem.sites。只是为了消除任何类加载器问题。 –