SAP Knowledge Base Article - Preview

3492989 - The spring bean orderMetricsSubmitOrderStrategy can not be found in local environment

Symptom

When following the official documentation for ensuring license compliance in the local environment, you may see the message "no strategy orderMetricsSubmitOrderStrategy found - not submitting order xxxx" in the logs when executing the sample code below.

import de.hybris.platform.core.Registry;
import de.hybris.platform.core.model.order.OrderModel;
import de.hybris.platform.order.strategies.SubmitOrderStrategy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;


public class OrderMetricsHelper
{

    private static final Logger LOG = LoggerFactory.getLogger(OrderMetricsHelper.class);
    private static final String BEAN_ID = "orderMetricsSubmitOrderStrategy";

    /**
     * Triggers order metrics collection for the specified order on Commerce Cloud environments. Outside of that context
     * it will act as no-op and only log a warning that the order could not be submitted.
     */
    public static void triggerMetrics(final OrderModel order)
    {
        final SubmitOrderStrategy bean = tryToFindBean();
        if (bean != null)
        {
            bean.submitOrder(order);
        }
        else
        {
            LOG.warn("no strategy {} found - not submitting order {}", BEAN_ID, order.getCode());
        }
    }

    static SubmitOrderStrategy tryToFindBean()
    {
        try
        {
            return Registry.getCoreApplicationContext().getBean(BEAN_ID, SubmitOrderStrategy.class);
        }
        catch (final BeansException e)
        {
            LOG.debug("Error finding order metrics bean", e);
            return null;
        }
    }
}

Image/data in this KBA is from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental.


Read more...

Environment

  • Product version: All SAP Commerce on-premise versions

Product

SAP Commerce Cloud all versions ; SAP Commerce all versions

Keywords

orderMetricsSubmitOrderStrategy,ordermetrics,ensuring,license,compliance , KBA , CEC-SCC-PLA-PL , Platform , Problem

About this page

This is a preview of a SAP Knowledge Base Article. Click more to access the full version on SAP for Me (Login required).

Search for additional results

Visit SAP Support Portal's SAP Notes and KBA Search.