Search code examples
sap-commerce-cloud

Hybris Populator. ClassNotFoundException "de.hybris.platform.commercefacades.convert.impl.DefaultConfigurablePopulator"


H! I wanted to create custom populator, and add to defaultProductConfiguredPopulator, but it throws exception

my custom-spring.xml

<bean id="defaultProductConfiguredPopulator" class="de.hybris.platform.commercefacades.converter.impl.DefaultConfigurablePopulator">
    <property name="populators">
        <map key-type="de.hybris.platform.commercefacades.product.ProductOption">
            <entry key="PHYSICAL_DIMENSIONS" value-ref="customProductPopulator"/>
        </map>
    </property>
</bean>

Thrown exception:

 org.springframework.beans.FatalBeanException: Context hybris Global Context Factory  couldn't  be created correctly due to, Error creating bean with name 'applicationEventMulticaster': Unsatisfied dependency expressed through method 'setAllDecorators' parameter 0; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [de.hybris.platform.commercefacades.converter.impl.DefaultConfigurablePopulator] for bean with name 'defaultProductConfiguredPopulator' defined in class path resource [customextension-spring.xml]; nested exception is java.lang.ClassNotFoundException

And my Populator class is simple:

public class CustomProductPopulator implements ConfigurablePopulator<ProductModel, ProductData, ProductOption> {
@Override
public void populate(final ProductModel source, final ProductData target, final Collection<ProductOption> options)
{
    target.setCode(source.getCode());
    if (options.contains(ProductOption.PHYSICAL_DIMENSIONS))
    {
        target.setWeight(source.getWeight());
        target.setHeight(source.getHeight());
    }
}

}

Thanks!


Solution

  • The class de.hybris.platform.commercefacades.converter.impl.DefaultConfigurablePopulator belongs to the commercefacades extension, the class where you are trying to create your beans must depends on this extension.

    But I would suggest a different approach. By doing

    <bean id="defaultProductConfiguredPopulator" class="de.hybris.platform.commercefacades.converter.impl.DefaultConfigurablePopulator">
        <property name="populators">
            <map key-type="de.hybris.platform.commercefacades.product.ProductOption">
                <entry key="PHYSICAL_DIMENSIONS" value-ref="customProductPopulator"/>
            </map>
        </property>
    </bean>
    

    You are writing a new bean overdding the old one, maybe you should try

        <bean id="myCustomConfiguredPopulator" parent="defaultProductConfiguredPopulator">
        <property name="populators">
            <map key-type="de.hybris.platform.commercefacades.product.ProductOption" merge="true">
                <entry key="PHYSICAL_DIMENSIONS" value-ref="customProductPopulator"/>
            </map>
        </property>
    </bean>
    

    Or

    <alias name="myCustomProductConfiguredPopulator" alias="productConfiguredPopulator"/>
    <bean id="myCustomProductConfiguredPopulator" class="de.hybris.platform.commercefacades.converter.impl.DefaultConfigurablePopulator">
        <property name="populators">
            <map key-type="de.hybris.platform.commercefacades.product.ProductOption">
            <entry key="PHYSICAL_DIMENSIONS" value-ref="customProductPopulator"/>
        </map>
    </property>
    

    Also, de.hybris.platform.commercefacades.converter.impl.DefaultConfigurablePopulator is Deprecated since 6.0. Does it works if you use de.hybris.platform.converters.impl.DefaultModifableConfigurablePopulator?