cancel
Showing results for 
Search instead for 
Did you mean: 

How to override bean in backoffice web context

Former Member
0 Kudos

I defined a custom CockpitThreadContextCreator in mybackoffice-backoffice-spring.xml to add some additional session attributes to a newly created context:

 <alias name="myThreadContextCreator" alias="cockpitThreadContextCreator"/>
 <bean id="myThreadContextCreator" parent="backofficeCockpitThreadContextCreator" class="com.mybackoffice.MyThreadContextCreator">
 </bean>

The bean gets instantiated successfully but is never used at runtime. Instead the default backofficeCockpitThreadContextCreator is used. How can i override the default implementation?

Accepted Solutions (1)

Accepted Solutions (1)

I just wan't to add that you don't need to modify the Web.xml of the backoffice extension to load new spring configurations from your backoffice extension as in or soluntions.

Yo can use the HybrisBackoffice.additionalWebSpringConfigs.mybackoffice property in the proyect properties on your backoffice extension to load an additional spring file to the backoffice web context. for example:

 HybrisBackoffice.additionalWebSpringConfigs.mybackoffice=classpath:/mybackoffice/spring/import.xml

this will search for import.xml at

 /mybackoffice/resources/mybackoffice/spring/import.xml
Former Member
0 Kudos

That's really interesting! thanks a lot!

Former Member
0 Kudos

That helped me! Thanks!

former_member329056
Discoverer
0 Kudos

This is definitely a better solution than customizing web.xml via customize folder or build callbacks.

Answers (6)

Answers (6)

0 Kudos
0 Kudos

Yes this is the best answer and the hybris intended way of doing it.

Former Member
0 Kudos

I've experienced the same problem, and indeed there does not seem to be an OOTB Hybris solution to adapt the logic of the backoffice-web defined beans. I've seen the solution of , but there is quite some modifications to the buildcallbacks, moving files around, so I've implement a different (and easier?) strategy. What I've done:

  1. I've created a custom web spring xml file in the custom backoffice extension: mybackoffice/resources/mybackoffice-web-spring.xml

  2. In this file, I override/change/... beans defined in the backoffice extensions web-spring xml

  3. The trick that I've applied is to update the buildcallbacks.xml to include this custom web context in the web-app-context of the backoffice application (this means including the custom web xml file in the contextConfigLocation list)

  4. Compile and run

The modifications to the buildcallbacks.xml are the following:

 <macrodef name="mybackoffice_after_build">
     <sequential>
         ...
         <replaceregexp
             file="${ext.backoffice.path}/web/webroot/WEB-INF/web.xml"
             match="backoffice-web-spring.xml(?!,)"
             replace="backoffice-web-spring.xml,classpath:mybackoffice-web-spring.xml"/>
     </sequential>
 </macrodef>

The result of those modifications can be seen in the backoffice extensions web.xml file:

 <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>
         WEB-INF/backoffice-web-spring.xml,classpath:mybackoffice-web-spring.xml
     </param-value>
 </context-param>

For me those adaptions work, and seem to be quite easy to achieve what I need.

Former Member
0 Kudos

So this can be done! I've done it, but it does take some setup, configuration, and leveraging the 'customize' ant target. It's a simple process, but takes a few minutes to setup. I have documented it here: http://www.daharveyjr.com/hybris-how-to-override-a-bean-in-backoffice-web-spring-xml/

If this link isn't allowed, let me know and I'll re-adjust. It just took a longer write-up than easily done here!

Former Member
0 Kudos

Drew I am not able to solve my issue. The bean is still not getting declared. Applicationcontext.containsbean() returns null in my case. I have also tried the below approach but it is just not working.

Former Member
0 Kudos

Has anyone resolved this ?

Former Member
0 Kudos

Has anyone resolved this? I've got the same issue with overriding another bean located in backoffice-web-spring.xml.

Thanks, Dimitar

Thanks, Dimitar

Former Member
0 Kudos

If you define your bean with the same ID then it's a matter of sequence of instantiation if your bean is used or the default one. Make sure to set up a dependency to the standard extension to make sure yours is loaded after.

Former Member
0 Kudos

My backoffice extension already has a dependency to the standard backoffice extension. The backofficeCockpitThreadContextCreator is defined in backoffice-web-spring.xml and aliased with cockpitThreadContextCreator like my bean. The context of my bean does not seem to affect the backoffice web context.