cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with OCC extension in 2211 and storefront

bliegener
Participant
0 Kudos

Hi all,

Based on the instructions for 2211, I created a new OCC extension using the "yocc" template.

I also created a custom controller, that uses the "dataMapper" bean:

@Resource(name = "dataMapper")
private DataMapper dataMapper;

This works totally fine in the OCC extension, but the storefront refuses to start as the spring context cannot initialize the controller due to the fact that it cannot load the dataMapper bean.

So I'm wondering if there is something wrong in my configuration? There is no dependency between the new occ extension and the storefront.

adamreisberg
Active Participant
0 Kudos

Hi benedikt.liegener

Are you running both legacy Accelerator-based storefront and the OCC-based "commercewebservices"?

bliegener
Participant
0 Kudos

adamreisberg

Yes, that is correct.

We have the legacy Accelerator-based storefront and the OCC-based "commercewebservices" running.

Accepted Solutions (0)

Answers (1)

Answers (1)

safin
Advisor
Advisor

Hi benedikt.liegener,

As you create an yocc based extension, please make sure the extension name will end with "occ", such as testocc, funcocc, etc. This is because:

in the current implementation, commercewebservices extension (all default OCC functionalities are implemented here) will scan all *-web-spring.xml in classpath which extension name must match *occ in order to load related OCC controllers.

On the other hand, as you create an extension based on yocc template, but the extension name doesn't follow this pattern, it means this extension will be just a normal extension, which will not become part of the whole OCC services, so your controller class will be not run in the spring web context. Unfortunately, the default data mapper implementation is registered in spring web context. I guess this is the reason you cannot dependency inject data mapper.

Please check whether or not your extension name ends with occ, if not, change it with occ as the suffix.

Furthermore, i also suggests to check #yourextensionName#-spring.xml to make sure you doesn't configure your controller here.

Best

Gang

bliegener
Participant
0 Kudos

Hi safin,

yes, the extension is names with "occ" as suffix.

As said, it works inside the OCC services, I can also see use the new extensions/controller inside the Swagger UI and so one.

Problem is the storefront, it seems that it also tries to create the spring bean for the OCC controller but fails due to the fact that it cannot inject the data mapper (because it is located in spring web context of commercewebservices).

safin
Advisor
Advisor

did you configure the controller in #yourextensionName#-spring.xml? if yes, just remove it.

If possible, please paste your controller, related #yourextensionName#-spring.xml and the exception log.

bliegener
Participant
0 Kudos

> did you configure the controller in #yourextensionName#-spring.xml? if yes, just remove it.

No, that haven't been done.Setup is as follows:

  • yxzmodulesocc extension created from 'yocc' template
  • Controller in (src): com.xyz.modules.occ.controllers

My controller looks the following:

@Controller
@Tag(name = "XYZ Products")
@RequestMapping(value = "/{baseSiteId}/xyzproducts")
public class XYZProductsController extends XYZProductsSearchController { ... }
@Controller
public class XYZProductsSearchController {

@Resource(name = "dataMapper")
private DataMapper dataMapper; ... }

xyzmodulesocc-web-spring.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">;

<context:component-scan base-package="com.xyz.modules.occ.controllers"/>

<bean parent="fieldSetLevelMapping">
<property name="dtoClass" value="de.hybris.platform.commercewebservicescommons.dto.product.ProductWsDTO"/>
<property name="levelMapping">
<map>
<entry key="BASIC" value="catalogId"/>
<entry key="DEFAULT" value="catalogId,equipmentDependencies,netPrice,netPrice"/>
<entry key="FULL" value="catalogId,equipmentDependencies,netPrice,netPrice" />
</map>
</property>
</bean>

</beans>

xyzmodules-spring.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">;

<context:annotation-config/>

<bean id="xyzSearchQueryCodec"
class="com.xyz.modules.occ.util.ws.impl.DefaultXYZSearchQueryCodec"/>

</beans>
safin
Advisor
Advisor
0 Kudos

would you please paste the exception logs here if possible?

bliegener
Participant
0 Kudos

Error Message is:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XYZProductsController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dataMapper' available

But this error message only occurs on the "accstorefront" service! The "api" service on which the OCC endpoint is running is working fine!

safin
Advisor
Advisor
0 Kudos

How do you know the error message occurs on the accstorefront? would you please paste the related logs indicating it comes from accstorefront?

i suspect you have another controller named 'XYZProductsController' in your accstorefront related web context, as you know accstorefront and occ are different web context, would you please check it?

bliegener
Participant
0 Kudos

In the log the message is coming of the accstorefront aspect. Additionally, 'accstorefront' is the only service/aspect that is not starting due to that error. When I remove the XYZProductsController in the 'occ' extension, it is working.
I also checked twice, it is the only XYZProductsController in the project, there is no other controller with the same name in the accstorefront.

safin
Advisor
Advisor
0 Kudos

it seems accstorefront aspect (service) is trying to load your created extension, maybe you need to check which web extensions are loaded in accstorefront aspect, then check whether XYZProductsController is implicitly referenced by one web extension.

bliegener
Participant
0 Kudos

Yes, that was also my assumption.

But regarding the "webapps" in the manifest.json, the only entry for "commercewebservices" is in the "api" aspect:

            "webapps": [
{
"name": "commercewebservices",
"contextPath": "/occ"
},

In the "accstorefront" aspect, there isn't such an entry.
I mean, basically all extensions are loaded in every aspect, right? Or is there a way to exclude extensions specifically from a certain aspect?