cancel
Showing results for 
Search instead for 
Did you mean: 

How to override bean in backoffice web context

Former Member
0 Kudos
3,856

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?

View Entire Topic
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.