我已经为我的 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);
关于java - 从 hybris hMC 操作中以编程方式检索 Spring bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18143744/