Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么父类中的字段在其他类(Java/apache sling)中使用时具有空值_Java_Osgi_Sling - Fatal编程技术网

为什么父类中的字段在其他类(Java/apache sling)中使用时具有空值

为什么父类中的字段在其他类(Java/apache sling)中使用时具有空值,java,osgi,sling,Java,Osgi,Sling,在我的java代码中,我有以下类: @Model(adaptables = SlingHttpServletRequest.class) public class ListModel extends SomeList{ @Inject protected ResourceResolver resourceResolver; //this method works fine: public List<String> getAllData(){

在我的
java
代码中,我有以下类:

@Model(adaptables = SlingHttpServletRequest.class)
public class ListModel extends SomeList{

    @Inject
    protected ResourceResolver resourceResolver;

    //this method works fine:
    public List<String> getAllData(){
        System.out.println(resourceResolver.getUserID());
    }
}
为什么第二类中的resourceResolver有空值

我还尝试移动此代码:

@Inject
protected ResourceResolver resourceResolver;

ListModel
MyNextListModel
,但即使如此,它在第二个类中仍然为空

如果从模型继承的类缺少@model注释,sling也不知道该怎么办。只需将注释添加到继承类中,代码就可以工作了。顺便说一句,确保另一个类也在一个包中,该包在核心Pom中注册为sling models包。

您是否尝试了super.resourcesolver.getUserID()?Kyle,我尝试了,但没有成功,不幸的是,我现在无法检查这一点,但我相信Sling需要使用
@Model
注释对子类本身进行注释。它不是在超级课堂上寻找它。尝试将
@Model(adapteables=SlingHttpServletRequest.class)
添加到
MyNextListModel
@Inject
protected ResourceResolver resourceResolver;