Skip to Content
author's profile photo Former Member
Former Member

How to override bean in backoffice web context

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?

Add a comment
10|10000 characters needed characters exceeded

Related questions

7 Answers

  • Best Answer
    Posted on Nov 13, 2017 at 04:21 PM
    11

    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
    
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 14, 2017 at 05:31 PM

    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!

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • author's profile photo Former Member
    Former Member
    Posted on May 19, 2017 at 01:57 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 12, 2018 at 02:11 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 15, 2015 at 09:29 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • author's profile photo Former Member
    Former Member
    Posted on Dec 21, 2016 at 03:40 PM

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

    Thanks, Dimitar

    Thanks, Dimitar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 26, 2017 at 11:56 AM

    Has anyone resolved this ?

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.