当我尝试调用http://:4502 / products.html
实际结果应列出书店应用程序的产品页面
答案 0 :(得分:0)
从我看到的,你在RankingServiceImpl:277
中得到NullPointerException,因为repository
字段为空。我能解释的唯一方法就是SCR注释在构建期间不会触发。
说,我真的很惊讶你的捆绑开始于CQ 5.5,因为依赖似乎是早期版本(5.4我想) - 我建议在/system/console/bundles
下仔细检查(搜索 CRX - 示例书店演示)。如果您缺少那里的导入,请尝试使用/src/impl/com.day.crx.sample.bookshop.bnd
来更新CQ 5.5中的版本,或者在CQ 5.4上运行。
答案 1 :(得分:0)
RankingServiceImpl中的注释似乎适用于CQ和CRX的早期版本。以下是我为实现此目的所做的更改:
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
/**
* Default implementation of the ranking service.
* The ranking is updated through observation (based on OSGi events).
* The service can be used by clients to get the highest ranked products.
*/
@Component(immediate = true)
@Service(value = RankingService.class)
@Property(name = org.osgi.service.event.EventConstants.EVENT_TOPIC, value = SlingConstants.TOPIC_RESOURCE_ADDED)
public class RankingServiceImpl
implements RankingService, EventHandler, Runnable {
private Logger logger = LoggerFactory.getLogger(this.getClass());
// private Logger logger = LoggerFactory.getLogger("RankingServiceImpl");
private static final String PROPERTY_PREV_RANKING = "lowerRankingRef";
private static final String PROPERTY_NEXT_RANKING = "higherRankingRef";
private static final int SHOW_HIGHEST_RANKING = 3;
/** Flag for stopping the background service. */
private volatile boolean running = false;
/** A local queue for handling new orders. */
protected final BlockingQueue<String> orders = new LinkedBlockingQueue<String>();
@Reference
private SlingRepository repository;
@Reference
private ResourceResolverFactory resourceResolverFactory;