java-从hybris hMC Action中以编程方式检索Spring bean
作者:互联网
我已经为我的hMC编写了自定义的SaveAction,我想在此操作中使用一些服务,例如modelService.
我想以编程方式进行此操作,而不是通过在我的spring xml文件中声明它,因为我的自定义SaveAction本身不是spring bean.
这是我想要的示例:
public class MySaveAction extends GenericItemSaveAction
{
@Override
protected ActionResult afterSave(final Item item, final DisplayState displayState, final Map currentValues,
final Map initialValues, final ActionResult actionResult)
{
ActionResult result = null;
result = super.afterSave(item, displayState, currentValues, initialValues, actionResult);
//how do I retrieve the modelService spring bean here?
final ModelService modelService = null;
final VariantProductModel variantProduct = modelService.get(item.getPK());
return result;
}
解决方法:
使用hybris,可以为此使用类de.hybris.platform.core.Registry,如下所示:
final ModelService modelService = Registry.getApplicationContext().getBean("modelService", ModelService.class);
标签:hybris,java 来源: https://codeday.me/bug/20191030/1968811.html