资源解析器通过吊索模型返回为空 [英] Resource Resolver returned as null via sling models

查看:102
本文介绍了资源解析器通过吊索模型返回为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过悬吊模型注入时,资源解析器返回为null,让我知道是否缺少任何东西:

Resource Resolver is being returned as null while injecting through sling models, let me know if anything I am missing :

我尝试过:

@Model(adaptables = Resource.class)
public class Navigation {

   @Inject  @Source("sling-object")
   private ResourceResolver resourceResolver;

}

我也尝试过:

@Model(adaptables = Resource.class)
public class Navigation {

  @Inject
  private ResourceResolver resourceResolver;

}

在两种情况下,它都被返回为null并抛出空指针异常。

In both cases it was being returned as null and throwing a null pointer exception.

让我知道纠正该错误的可能。

Let me know what I may be missing to correct this error.

推荐答案

这对我来说使用的是 @SlingObject 注释,而不是 @Inject @Source 。从理论上讲,他们应该做同样的事情,但我想我会给这个答案一个答案,以防万一它对别人也有帮助。

This is working for me using the @SlingObject annotation, rather than @Inject and @Source. Theoretically they should be doing the same thing, but figured I'll add this an answer just in case it helps someone else as well.

@Model(adaptables = Resource.class)
public class Navigation {

  @SlingObject
  private ResourceResolver resourceResolver;

}

这篇关于资源解析器通过吊索模型返回为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆