SAP Hybris自定义促销动作Bean发布报错:未找到对应Bean
问题
在SAP Hybris中创建了自定义促销动作类Task9ProductNameAction,继承自AbstractRuleExecutableSupport,代码如下:
package tr.nttdata.csa.csapromotionengineservices.rule.ruledifinitons.conditions; public class Task9ProductNameAction extends AbstractRuleExecutableSupport { private final String SELECT_OPERATOR = "selectOperator"; @Override public void performAction(RuleActionContext context) { performActionInternal(context); } @Override protected boolean performActionInternal(RuleActionContext context) { CartRAO cart = context.getValue(CartRAO.class); Set<OrderEntryRAO> orderEntries = cart.getEntries(); if (CollectionUtils.isEmpty(orderEntries)) return false; Task9Operator discountType = (Task9Operator) context.getParameter(SELECT_OPERATOR); BigDecimal discountAmount = (BigDecimal) context.getParameter("discountAmount"); Optional<OrderEntryRAO> targetEntryOptional = getTargetEntry(orderEntries, discountType); if (targetEntryOptional.isPresent()){ OrderEntryRAO orderEntry = targetEntryOptional.get(); applyDiscount(context, orderEntry, discountAmount); return true; } return false; } private Optional<OrderEntryRAO> getTargetEntry(Set<OrderEntryRAO> orderEntries, Task9Operator discountType){ if (discountType == Task9Operator.LOWEST){ return orderEntries.stream().min(Comparator.comparing(OrderEntryRAO::getTotalPrice)); } else if (discountType == Task9Operator.HIGHEST){ return orderEntries.stream().max(Comparator.comparing(OrderEntryRAO::getTotalPrice)); } else { return Optional.empty(); } } private void applyDiscount(RuleActionContext context, OrderEntryRAO orderEntry, BigDecimal discountAmount){ DiscountRAO discount = new DiscountRAO(); discount.setValue(discountAmount); discount.setAppliedToQuantity(orderEntry.getQuantity()); RuleEngineResultRAO result = context.getRuleEngineResultRao(); result.getActions().add(discount); setRAOMetaData(context, discount); context.insertFacts(discount); context.scheduleForUpdate(orderEntry, orderEntry.getOrder(), result); } }
随后在promotionengineservices-spring.xml中定义Bean:
<alias name="task9ProductNameAction" alias="task9ProductNameAction"/> <bean id="task9ProductNameAction" parent="abstractRuleExecutableSupport" class="tr.nttdata.csa.csapromotionengineservices.rule.evaluation.actions.Task9ProductNameAction"> </bean>
最后编写Impex配置:
INSERT_UPDATE RuleActionDefinition; id[unique = true] ; priority; translatorId ; translatorParameters ; categories(id) ; y_product_name_action ; 350 ; ruleExecutableActionTranslator ; actionId->task9ProductNameAction ; product_discounts INSERT_UPDATE RuleActionDefinitionParameter; definition(id)[unique = true] ; id[unique = true] ; priority ; type ; value; required[default = true] ; y_product_name_action ; selectOperator ; 150 ; Enum(tr.nttdata.csa.csapromotionengineservices.rule.ruledifinitons.Task9Operator) ; ; ; y_product_name_action ; discountAmount ; 150 ; java.math.BigDecimal ; ; INSERT_UPDATE RuleActionDefinitionRuleTypeMapping; definition(id)[unique = true] ; ruleType(code)[default = 'PromotionSourceRule'][unique = true] ; y_product_name_action ;
发布促销时出现编译错误,日志提示:Rule Code "task9_promotion": "No bean found for action",完整日志:
INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] ************************************* INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] Starting RuleEngineCompilePublishJob INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] ************************************* ERROR [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [DefaultRuleMaintenanceService] The rule compilation finished with errors ERROR [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] Rule Code "task9_promotion": "No bean found for action" INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] ************************************* INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] RuleEngineCompilePublishJob finished with errors INFO [00055LBU::de.hybris.platform.ruleengineservices.jalo.RuleEngineJob] (00055LBU) [AbstractRuleEngineJob] *************************************
原因分析
- 类包路径不匹配:Java类实际包路径为
tr.nttdata.csa.csapromotionengineservices.rule.ruledifinitons.conditions,但Spring配置中指定的class路径是tr.nttdata.csa.csapromotionengineservices.rule.evaluation.actions.Task9ProductNameAction,路径不一致导致Spring无法找到类实例化Bean。 - 无效Spring别名配置:
<alias name="task9ProductNameAction" alias="task9ProductNameAction"/>是重复无效配置,别名与原Bean名称完全相同,无实际作用且可能干扰Bean加载逻辑。 - Bean未成功注册:若Spring无法实例化Bean,Impex中
actionId->task9ProductNameAction的映射会失效,规则编译时找不到对应的动作Bean。
解决方案
1. 修正Spring配置的类路径
将Spring配置中的class路径改为Java类实际所在的包路径,同时删除无效别名配置:
<!-- 删除无效的别名配置 --> <!-- <alias name="task9ProductNameAction" alias="task9ProductNameAction"/> --> <bean id="task9ProductNameAction" parent="abstractRuleExecutableSupport" class="tr.nttdata.csa.csapromotionengineservices.rule.ruledifinitons.conditions.Task9ProductNameAction"> </bean>
2. 验证Bean注册状态
- 启动Hybris服务后,通过HAC的Bean Browser搜索
task9ProductNameAction,确认Bean是否成功注册。 - 若未找到,检查模块的Spring配置文件是否被正确引入(需在模块的
*-spring.xml或web-spring.xml中确保promotionengineservices-spring.xml被加载)。
3. 重新导入Impex并发布规则
- 重新执行Impex导入,确保
RuleActionDefinition中的translatorParameters正确映射到Bean id。 - 重新触发规则编译发布任务,检查日志是否消除错误。
内容的提问来源于stack exchange,提问作者canercin
相关产品推荐
相关产品推荐

