cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use custom filters in yocc extension of Hybris 2211

andybugatto
Explorer

I developed a filter and wanted to use it in the OCC extension

issing bean 'commerceWebServicesFilterChainListV2'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'commerceWebServicesFilterChainListV2' available

I guess the error is because commerceWebServicesFilterChainListV2 is declared in the web package and yocc extension is declaring in src package.

The question now is. What's the proper way to do this? besides not listenning to SAP and using the yoccaddon

Accepted Solutions (1)

Accepted Solutions (1)

adambadura
Participant

Have a look at /commercewebservices/web/webroot/WEB-INF/config/v2-web-spring.xml:

<!-- Extension point to inject beans from other sources -->

<import resource="classpath*:/occ/v2/*occ/web/spring/*-web-spring.xml"/>

<import resource="classpath*:/commercewebservices/v2/additional-web-spring-context.xml"/>

You can put additional spring config files that will be loaded into OCC web spring context without the need to put them in the web part of your extension (so you can just be using yocc template).

For example: /hybris/bin/modules/configurator-complex-products/sapproductconfigocc/resources/occ/v2/sapproductconfigocc/web/spring/sapproductconfigocc-web-spring.xml

And a link to documentation: https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/3476714bba0b4cb9b3eb58c270e44439/8ef2d8d7b...

andybugatto
Explorer
0 Kudos

Hello Adam,

thanks for you reply. I setup a new project to test your suggestions and it doesn't work. Have you tried this?

I'm going to leave screenshots of what I've done.

adambadura
Participant
0 Kudos

Hi Andy,

Yes I did actually use that in one of my projects:

  1. I have an OCC extension generated from yocc with dependency to
  2. In this extension i have a file: /<extensionname>/resources/occ/v2/<extensionname>/web/spring/<extensionname>-web-spring.xml with custom filters and controllers e.g.
    <bean id="customSessionCurrencyFilter" class="(...).CustomSessionCurrencyFilter"/>

    <bean depends-on="commerceWebServicesFilterChainListV2" parent="listMergeDirective">
    <property name="add" ref="customSessionCurrencyFilter"/>
    <property name="afterBeanNames">
    <list value-type="java.lang.String">
    <value>commerceWebServicesSessionCurrencyFilterV2</value>
    </list>
    </property>
    <property name="beforeBeanNames">
    <list value-type="java.lang.String">
    <value>cartMatchingFilter</value>
    </list>
    </property>
    </bean>

Please check in the logs if your extension is actually loaded. You could also enable DEBUG logging for org.springframework to check if the spring config file is picked up by the platform.

Good luck!

adambadura
Participant
0 Kudos

andybugatto You need to set the name of your OCC extension so that it ends with *occ (e.g. trainingocc). Have a look at this pattern: "classpath*:/occ/v2/*occ/web/spring/*-web-spring.xml":

  • It will not pick up a file /occ/v2/training/web/spring/training-web-spring.xml
  • It would pick up a file /occ/v2/trainingocc/web/spring/trainingocc-web-spring.xml

Answers (0)