【发布时间】:2017-06-13 05:11:43
【问题描述】:
我的 Sling 模型中的 javax.annotation.PostConstruct 注释存在问题。
使用我的模型的 html 文件:
<div data-sly-use="com.company.platform.component.general.textblockvalidator.TextBlockValidatorModel" data-sly-unwrap />
型号:
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.models.annotations.Model;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
@Model(adaptables = org.apache.sling.api.resource.Resource.class)
public class TextBlockValidatorModel {
@PostConstruct
private void init() {
System.out.println();
}
public String getValidate(){
return "This works";
}
}
我可以从我的文件中调用 getter,但我似乎从未进入我的 @PostConstruct init() 方法。
IntelliJ 确实在注释上给了我一个警告,但我不确定我做错了什么:
吊索模型包:
<Sling-Model-Packages>
...
com.asadventure.platform.component
...
</Sling-Model-Packages>
有什么想法吗?提前致谢!
【问题讨论】:
-
什么是 AEM 版本?
-
我猜你不能在
init()方法上添加@PostConstruct注解。 -
@i.net 我们使用的是 6.1 版
-
FWIW,只要您的包的依赖范围设置为提供并且适用,就可以忽略 intellij 警告。我认为这只是 intellij 设计中提供的依赖项的警告
-
您确定您的模型实际上是使用吊索模型创建的吗?请检查您是否在 pom.xml maven-bundle-plugin 配置中注册了您的包,您应该有类似
<Sling-Model-Packages>your.package</Sling-Model-Packages>的内容
标签: annotations osgi adobe aem sling