JSP / Controller not found for custom component in Hybris addon

匆匆过客 提交于 2019-12-24 00:55:27

问题


I’m running Hybris 6.6 and are building a new addon, that is basically a controller and corresponding JSP. During runtime however, Hybris isn’t finding the controller bean and searches for JSP in the storefront folder (it’s not there, since the JSP is in the storefront addon folder).

I created the addon using extgen, and then installed it in the storefront using also ant.

Steps:

  • Created component in -items.xml inheriting from SimpleCMSComponent
  • Created controller inheriting from AbstractCMSController,
  • Created JSP in addon folder,
  • Created component and added to page slot via Imped,
  • @Controller has the name equal to component + “Controller”

I’ve debuged the code, and when Hybris tries to find if there is a controller via getBeanFactory().contains(controller) it returns false. If I look at the bean list that the bean factory returns, the bean for the controller is not there.

Any clues on what’s happening? I’ve even tried to create the controller bean explicitly on the -web-spring.xml but doesn’t change anything.

Thank you


回答1:


Make sure

  • Your controller should extends GenericCMSAddOnComponentController or AbstractCMSAddOnComponentController for the compoent inside addon.
  • Annotate the Controller with

    @Controller(YourComponentController) @RequestMapping(value="/view/YourComponentController")

  • Add your jsp to *addon/web/webroot/*/view/*/cms/yourcomponentname.jsp. Refer getView method of AbstractCMSAddOnComponentController for the path

  • *-web-spring.xml should be in resource folder/path

  • component scan should be added for your controller in *-web-spring.xml

    <context:component-scan base-package="my.path.controllers"/>

  • *-web-spring.xml is there in additionalWebSpringConfigs properties. Refer your addon project.properties

    like myCustomstorefront.additionalWebSpringConfigs.MyAddonName=classpath:/XXX/web/spring/*-web-spring.xml




回答2:


In addition to the excellent instructions by HybrisHelp, it's likely that others coming across this question need to add this to the *-web-spring.xml

scope-resolver="de.hybris.platform.spring.IgnoreTenantScopeMetadataResolver"

so it looks like

<context:component-scan base-package="my.path.controllers" scope-resolver="de.hybris.platform.spring.IgnoreTenantScopeMetadataResolver" />

Only with this attribute, the controller was loaded for me.



来源:https://stackoverflow.com/questions/52035370/jsp-controller-not-found-for-custom-component-in-hybris-addon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!