broadleaf-commerce

Class transformation errors with ProductOptionValueImpl - Broadleaf commerce


I have developed an application using broadleaf commerce. I try to implement dynamic pricing by following the document

https://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/pricing/dynamic-pricing-configuration

I implemented successfully and can start the application in eclipse. But when i try to start application in command line I got following error

java.lang.IllegalStateException: The classes [org.broadleafcommerce.core.catalog.domain.ProductOptionValueImpl] are managed classes within the MergePersistenceUnitManager but were not detected as being transformed by the EntityMarkerClassTransformer. There can be multiple causes for this: 1. Session persistence is enabled in your servlet container (like Tomcat) and an entity object has been loaded by the container before being loaded by the application's classloader. Ensure that session persistence i s disabled; in Tomcat ensure that a element exists in your context.xml. 2. You are inadvertently using class scanning to find a ServletContainerInitializer class, and your servlet container is loading all classes before transformers have been registered. If you are using a web.xml, ensu re that there is an element somewhere in that file. If you are not using a web.xml and are using Spring Boot, then you likely need to add one. See https://www.broadleafcommerce.com/docs/core/5. 2/broadleaf-concepts/key-aspects-and-configuration/app-server-configuration/tomcat for the example web.xml 3. The classes are being used as apart of an @Bean method or in some other runtime capacity that is initialized prior to persistence manager startup

I tried the solution mentioned in point 1 and 2, but couldn't get resolved.

Please help me to get out of this exception.

Edit : I have implemented DynamicSkuPricingService interface, inside It has an override method which is using ProductOptionValueImpl. Its actually creating problem.

   @Service("ecomDynamicSkuPricingService")
    public class EcomDynamicSkuPricingServiceImpl implements DynamicSkuPricingService {
   ....
    @Override
    public DynamicSkuPrices getPriceAdjustment(ProductOptionValueImpl productOptionValueImpl, Money priceAdjustment,
            @SuppressWarnings("rawtypes") HashMap skuPricingConsiderationContext) {
   ....
   }
}

Solution

  • I'm not sure this is the right way to fix this issue. But I placed following snippet in my custom DynamicSkuPricingFilter, its solved my problem

    @PostConstruct
    public void init() {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }
    

    or

    We can fix this issue by - not using @Autowired or @Resource to inject DynamicSkuPricingService in the custom DynamicSkuPricingFilter, but getting DynamicSkuPricingService bean from applicationcontext wherever we required.