cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Overriding SiteMapContext.java for generating custom sitemap.xml

0 Likes
917

Hi,

Our application requires to have <lastmod></lastmod> tag in sitemap.xml for which I need to extend class de.hybris.platform.acceleratorservices.sitemap.renderer.SiteMapContext and override init() method. But going through the code I found that SiteMapContext.java class bean does not have an alias in acceleratorservices-spring.xml and only a bean id.

Question - How can we override this class methods if there is no alias provided in spring.xml?

This bean id siteMapContext is being called in AbstractSiteMapGenerator as below

 (SiteMapContext) applicationContext.getBean("siteMapContext");

So even if I create a class by extending SiteMapContext and give a different bean id I will have to modify AbstractSiteMapGenerator class to use the new bean id.

What is the solution to this?

Accepted Solutions (1)

Accepted Solutions (1)

arvind-kumar_avinash
Active Contributor

Hi - the following method will work for you:

 <bean id="yourCustomSiteMapContext" class="your.package.YourCustomSiteMapContext">
     ...
     ...
     ...
 </bean>    
 
 <alias name="yourCustomSiteMapContext" alias="siteMapContext"/>

Please try it and let me know your feedback.

Answers (1)

Answers (1)

Former Member
0 Likes

Hi Zahid, you just need to create a new bean with the same bean id as OTB. eg:

 <bean id="siteMapContext"
           class="your custom class"
           scope="prototype">
         <property name="baseSiteService" ref="baseSiteService"/>
         <property name="siteBaseUrlResolutionService" ref="siteBaseUrlResolutionService"/>
         <property name="urlEncoderService" ref="urlEncoderService"/>
     </bean>
arvind-kumar_avinash
Active Contributor
0 Likes

While it is possible to do so, it is an error-prone approach. A quick google search will point you to hundreds of links discussing the problem with this approach. A couple of them are as follows:

  1. https://stackoverflow.com/questions/5849192/springs-overriding-bean

  2. https://www.codelooru.com/2017/02/overriding-spring-beans-with-aliases.html