我想为管理端(broadleaf 框架)创建自己的控制器,它扩展了 AdminBasicEntityController。有我的控制器代码: public class AdminArticleController extends AdminBasicEntityController { @Autowired private ArticleService articleService; @Override public String addEntity(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @ModelAttribute("entityForm") EntityForm entityForm, BindingResult result) throws Exception { return super.addEntity(request, response, model, pathVars, entityForm, result); } @Override public String saveEntityJson(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable("id") String id, @ModelAttribute("entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception { return super.saveEntityJson(request, response, model, pathVars, id, entityForm, result, ra);// articleService.updateArticleEntity(); }}我还在 AdminServletConfig 文件中添加了下一个代码:@Beanpublic AdminBasicEntityController adminBasicEntityController() { return new AdminArticleController();}
1 回答
开满天机
TA贡献1786条经验 获得超13个赞
你很亲近!要覆盖现有的 Broadleaf bean,请务必使用注释中声明的 bean 名称。将您的 bean 命名为“blAdminBasicEntityController”,如下所示:
@Bean
public AdminBasicEntityController blAdminBasicEntityController() {
return new AdminArticleController();
}
您看到的错误是由于有两个具有相同映射的 bean。发生这种情况是因为 AdminBasicEntityController 带有注释@Controller("blAdminBasicEntityController"),这意味着它将被组件扫描拾取并创建一个名为 的 bean blAdminBasicEntityController。由于 AdminArticleController 扩展了 AdminBasicEntityController,一旦创建了 AdminArticleController bean,AdminBasicEntityController 中的每个映射都会有 2 个映射。解决方案是覆盖 Broadleaf bean,而不是添加一个额外的。
添加回答
举报
0/150
提交
取消