Search code examples
springdependency-injectionsap-commerce-cloud

How to resolve FatalBeanException in Spring?


I get the following exception:

org.springframework.beans.FatalBeanException: Context hybris Global Context Factory couldn't be created correctly due to, Error creating bean with name 'modifyPopulatorList$child#0' defined in class path resource [config/cmsfacades-cmsitems-spring.xml]: Initialization of bean failed;

Error creating bean with name 'ordermanagementOrderConverter' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementOrderPopulator' while setting bean property 'populators' with key [0];

Error creating bean with name 'ordermanagementOrderPopulator' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementOrderEntryConverter' while setting bean property 'orderEntryConverter';

Error creating bean with name 'ordermanagementOrderEntryConverter' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementOrderEntryPopulator' while setting bean property 'populators' with key [0];

Error creating bean with name 'warehousingOrderEntryPopulator' defined in class path resource [warehousingfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementProductConverter' while setting bean property 'productConverter';

Error creating bean with name 'ordermanagementProductConverter' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementProductPopulator' while setting bean property 'populators' with key [0];

Error creating bean with name 'ordermanagementProductPopulator' defined in class path resource [ordermanagementfacades-spring.xml]: Error setting property values;

Invalid property 'designerConverter' of bean class [de.hybris.platform.ordermanagementfacades.product.converters.populator.OrdermanagementProductBasicPopulator]: Bean property 'designerConverter' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

This is my bean registration :

   <alias name="defaultCustomProductBasicPopulator" alias="productBasicPopulator"/>
    <bean id="defaultCustomProductBasicPopulator" parent="defaultProductBasicPopulator"
    class="de.hybris.NagAcc.facades.product.converters.populator.CustomProductBasicPopulator">
        <property name="designerConverter" ref="designerConverter" />
    </bean>

This is the class :

public class CustomProductBasicPopulator<SOURCE extends ProductModel, TARGET extends ProductData> extends ProductBasicPopulator<SOURCE,TARGET> {

    private Converter<DesignerModel,DesignerData> designerConverter;

    public Converter<DesignerModel, DesignerData> getDesignerConverter() {
        return designerConverter;
    }

    public void setDesignerConverter(Converter<DesignerModel, DesignerData> designerConverter) {
        this.designerConverter = designerConverter;
    }

    @Override
    public void populate(SOURCE productModel, TARGET productData) throws ConversionException {
        super.populate(productModel, productData);
        if (productModel.getDesigner() != null)
        {
            DesignerData designerData = getDesignerConverter().convert(productModel.getDesigner());
            productData.setDesigner(designerData);
        }
    }


This is the parent bean definition :

<alias name="defaultProductBasicPopulator" alias="productBasicPopulator"/>
    <bean id="defaultProductBasicPopulator" parent="baseProductPopulator"
          class="de.hybris.platform.commercefacades.product.converters.populator.ProductBasicPopulator">
        <property name="productConfigurableChecker" ref="productConfigurableChecker"/>
    </bean>

The complete stack trace:

  org.springframework.beans.FatalBeanException: Context hybris Global Context Factory  couldn't  be created correctly due to, Error creating bean with name 'modifyPopulatorList$child#0' defined in class path resource [config/cmsfacades-cmsitems-spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ordermanagementOrderConverter' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementOrderPopulator' while setting bean property 'populators' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ordermanagementOrderPopulator' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementOrderEntryConverter' while setting bean property 'orderEntryConverter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ordermanagementOrderEntryConverter' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementOrderEntryPopulator' while setting bean property 'populators' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'warehousingOrderEntryPopulator' defined in class path resource [warehousingfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementProductConverter' while setting bean property 'productConverter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ordermanagementProductConverter' defined in class path resource [ordermanagementfacades-spring.xml]: Cannot resolve reference to bean 'ordermanagementProductPopulator' while setting bean property 'populators' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ordermanagementProductPopulator' defined in class path resource [ordermanagementfacades-spring.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'designerConverter' of bean class [de.hybris.platform.ordermanagementfacades.product.converters.populator.OrdermanagementProductBasicPopulator]: Bean property 'designerConverter' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
        at de.hybris.platform.core.HybrisContextFactory.build(HybrisContextFactory.java:307)
        at de.hybris.platform.core.HybrisContextFactory$GlobalContextFactory.buildSelf(HybrisContextFactory.java:179)
        at de.hybris.platform.core.HybrisContextFactory$GlobalContextFactory.build(HybrisContextFactory.java:165)
        at de.hybris.platform.core.HybrisContextHolder.getGlobalInstanceCached(HybrisContextHolder.java:122)
        at de.hybris.platform.core.HybrisContextHolder.getGlobalInstance(HybrisContextHolder.java:101)
        at de.hybris.platform.core.HybrisContextHolder.getAppCtxFactory(HybrisContextHolder.java:152)
        at de.hybris.platform.core.HybrisContextHolder.getApplicationInstance(HybrisContextHolder.java:78)
        at de.hybris.platform.core.AbstractTenant.createCoreApplicationContext(AbstractTenant.java:758)
        at de.hybris.platform.core.AbstractTenant.doStartupSafe(AbstractTenant.java:799)
        ... 22 more

According to me all getters and setters are fine, I can not resolve this error. Please help.


Solution

  • I don't have access to hybris sources to have a look (thank god!), but I think it's worth to have a look at the Javadoc of OrdermanagementProductBasicPopulator:

    public void populate​(ProductModel productModel, ProductData productData) Description copied from interface: Populator Populate the target instance with values from the source instance. Overrides: populate in class ProductBasicPopulator

    So I guess, the class OrdermanagementProductBasicPopulator extends ProductBasicPopulator but the bean definition of OrdermanagementProductBasicPopulator has your productBasicPopulator as a parent, which means that spring tries to inject the property of your bean definition, which is not a property in the inheritance chain of OrdermanagementProductBasicPopulator.

    As mentioned, this is just a guess because I don't see the sources... If my guess is correct, it depends on your requirements how to get rid of this problem. You can either give your bean a new alias and modify the populator list(s) where necessary or you override the bean alias of OrdermanagementProductBasicPopulator accordingly.

    If thats's not the problem, please post the bean definition of OrdermanagementProductBasicPopulator.