为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Lombock 和构造函数注入的 Spring 注入 bean 为空

使用 Lombock 和构造函数注入的 Spring 注入 bean 为空

慕神8447489 2023-01-05 17:09:12
我正在将使用Spring实现的Maven项目迁移到Spring Boot 1.5.20.RELEASE。我有一个适配器类,它将由所有带注释的类扩展,@RestControllers以保证与前端的向后兼容性public class RestControllerAdapter {    private MessageTemplate messageTemplate;    private MessageTemplate getMessageTemplate() {        if (messageTemplate == null) {            messageTemplate = ApplicationContextUtils.getBean(MessageTemplate.class);        }        return messageTemplate;    }    protected final String message(@NonNull String code) {        return getMessageTemplate().getMessage(code);    }    protected final String message(@NonNull String code, Object... args) {        return getMessageTemplate().getMessage(code, args);    }    protected final ModelMap success() {        val map = new ModelMap();        map.put("success", true);        map.put("message", getMessageTemplate().getMessage("message.success.default"));        return map;    }    protected final ModelMap error(@NonNull String message) {        val map = new ModelMap(2);        map.put("success", false);        map.put("error", message);        return map;    }    protected final ModelMap retry(@NonNull Exception ex) {        val map = new ModelMap(3);        map.put("success", false);        map.put("error", ex.getMessage());        map.put("confirmar", true);        return map;    }    protected final ModelMap empty() {        return new ModelMap();    }    @ExceptionHandler(JpaSystemException.class)    public ModelMap handleJpaSystemException(JpaSystemException ex) {        log.error(ex.getMessage(), ex);        return createError(ex.getMostSpecificCause());    }    @ExceptionHandler(DataIntegrityViolationException.class)    public ModelMap handleDataIntegrityViolationException(DataIntegrityViolationException ex) {        log.error(ex.getMessage(), ex);        return createError(ex.getMostSpecificCause());    }}
查看完整描述

1 回答

?
慕村225694

TA贡献1880条经验 获得超4个赞

最后我解决了这个问题。

它与方法中的final关键字有关UserServiceImpl::update

它不允许注入过程正常工作并且它完全有意义,因为@Transactional不能注释的类final

我已经删除了它,现在一切正常。示例代码在这里


查看完整回答
反对 回复 2023-01-05
  • 1 回答
  • 0 关注
  • 79 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信