cancel
Showing results for 
Search instead for 
Did you mean: 

override controller Occ

stefaniaZ
Participant
0 Kudos

Good morning,

I need to override the B2BCartsController because I have to customize addCartEntry.

I follow this documentation https://help.sap.com/docs/SAP_COMMERCE_CLOUD_PUBLIC_CLOUD/e1391e5265574bfbb56ca4c0573ba1dc/03a3ca072...

I create My class that extend B2BCartsController and I add this:

@ApiOperation(nickname = "addOrgCartEntry", hidden = true, value = "Adds more quantity to the cart for a specific entry",
            notes = "Adds more quantity to the cart for a specific entry based on it's product code, if the product is already in the cart the amount will be added to the existing quantity.")
    @RequestMappingOverride(priorityProperty = "myprojectB2Bocc.myprojectB2BCartsController.addCartEntry.priority")
    @SiteChannelRestriction(allowedSiteChannelsProperty = API_COMPATIBILITY_B2B_CHANNELS)
    @RequestMapping(value = OCC_REWRITE_OVERLAPPING_BASE_SITE_USER_PATH + "/carts/{cartId}/entries", method = RequestMethod.POST)
    @ResponseBody
    @ApiBaseSiteIdUserIdAndCartIdParam
    public CartModificationWsDTO addCartEntry(
            @ApiParam(value = "Base site identifier.", required = true) @PathVariable final String baseSiteId,
            @ApiParam(value = "Code of the product to be added to the cart.", required = true) @RequestParam(required = true) final String code,
            @ApiParam(value = "Amount to be added.", required = false) @RequestParam(required = false, defaultValue = "1") final long quantity,
            @ApiFieldsParam @RequestParam(required = false, defaultValue = FieldSetLevelHelper.DEFAULT_LEVEL) final String fields)
    {
        final OrderEntryData orderEntry = getOrderEntryData(quantity, code, null);

        return dataMapper.map(cartFacade.addOrderEntry(orderEntry), CartModificationWsDTO.class, fields);
    }



I have this error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/Users/zanzotterste/work/myprojectSpartacus/core-customize/hybris/bin/modules/web-services-commons/webservicescommons/lib/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/Users/zanzotterste/work/myprojectSpartacus/core-customize/hybris/bin/modules/web-services-commons/webservicescommons/lib/springfox-spring-web-2.9.2.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in de.hybris.platform.commercewebservices.core.v2.config.WebConfig: Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'myprojectB2BCartsController' method 
com.nttdata.myproject.controllers.myprojectB2BCartsController#setPaymentType(String, String, String)
to {PUT [/{baseSiteId}/users/{userId}/carts/{cartId}/paymenttype]}: There is already 'b2BCartsController' bean method
de.hybris.platform.b2bocc.v2.controllers.B2BCartsController#setPaymentType(String, String, String) mapped.
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.19.jar:5.3.19]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.19.jar:5.3.19]
	at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.19.jar:5.3.19]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:41010) ~[spring-context-5.3.19.jar:5.3.19]
	at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:702) ~[spring-webmvc-5.3.19.jar:5.3.19]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:668) ~[spring-webmvc-5.3.19.jar:5.3.19]
	at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:716) ~[spring-webmvc-5.3.19.jar:5.3.19]<br>

but I do not understand the problem.

thanks

Stefania

Accepted Solutions (0)

Answers (2)

Answers (2)

safin
Advisor
Advisor

Hi Stefania,

please note,

(1) annotation based Url mapping can not be overridden

(2) this error will be thrown becasue you have two controllers configured with the same url and request method (one is the default B2BCartsController, the other is your customized controller).

The workaround is you can use different URL or the same URL with different parameters, but this is not good for your case since B2BCartsController has many URL mapping.

The recommended solution is that overwritten can happen at business layer, in other words, controller should be treated as a web based API and concrete logic is implemented by underlying service, you can consider to inject new service implementation for DataMapper interface to add your customization logic or something similar.

romitchhabra
Participant
0 Kudos

Hi Stefania,

From the error it looks that there is a method setPaymentType in myprojectB2BCartsController and may be @RequestMappingOverride annotation is missing from the top of that method.