How to Override a Bean in backoffice-web-spring.xml

Recently, I try to refactor one project and find one thing, in this project, it need to override some beans defined in the backoffice-web-spring.xml. Due to the beans belong to different web context, it can not be overridden in the customization extension. 

The current implementation refers to the blog https://www.daharveyjr.com/hybris-how-to-override-a-bean-in-backoffice-web-spring-xml/ 

The main steps are:

It uses the buildcallbacks.xml to copy the .class file to the OOTB backoffice extension to make hybris could find the customized classes. 

Use ant customize command to copy a new created xxxx-web-spring.xml configuration file into the proper path.

In this way, we could achieve the target and override the beans in the backoffice context, but this method is much complex than override beans in customization extension and if in the deployment environment, the path changed, we need to change the callback scripts. If I try to use jrebel, the hot deployment is broke by this copy class method. So, I try to find another simple and easy way to make this target happen.

After some investigations, there are some connections points(objectFacadeStrategy, typeFacadeStrategy etc) already provided by backoffice framework for Cockpit Data Integration Layer.

In the following example, I will try to override the objectFacadesStrategies and defaultObjectFacadeStrategy. Our new defaultObjectFacadeStrategy will handle all the items excpect order model, and the new created demoOrderFacadeStrategy will handel order model save operation.

1. Create a backoffice customization extension named demobackoffice

2. Override these strategies in the demobackoffice-backoffice-spring.xml file

3. Implement the object facade strategy in the path $HybrisHome/bin/customer/demobackoffice/backoffice/src

DemoPlatformObjectFacadeStrategy:

DemoOrderObjectFacadesStrategy:


4. Test it, in the backoffice, firstly, save a customer item, then save an order item, we will find the log in the console


Done! Enjoy, and the source code for this demo: https://github.com/baogang/demobackoffice

Reference:

https://www.daharveyjr.com/hybris-how-to-override-a-bean-in-backoffice-web-spring-xml/

https://help.hybris.com/6.4.0/hcd/8b7e07aa866910149f57b60f4fece66c.html

https://help.hybris.com/6.4.0/hcd/94ac56a0aa9f486490bbe1251d994457.html

你可能感兴趣的:(How to Override a Bean in backoffice-web-spring.xml)