【问题标题】:Spring proxied class with CGLIB - how to discover names of function's arguments带有 CGLIB 的 Spring 代理类 - 如何发现函数参数的名称
【发布时间】:2015-12-18 03:25:07
【问题描述】:

我想在代理对象上使用带有条件属性的@EventListener 注释。 EL 表达式使用函数的参数。但是在运行时org.springframework.core.LocalVariableTableParameterNameDiscoverer 无法从 CGLIB 生成的代理中读取调试信息,这就是无法访问参数的原因。结果我得到了

org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 92): 在 null 上找不到属性或字段“prop”
class InterestedInEvent {

    @EventListener(classes = SomeEvent.class, condition="#event.prop!=null")
    @CacheEvict(cacheNames = CACHE_FOR_SOMETHING, allEntries = true)
    public void onEvent(SomeEvent event) {
        logger.debug("Chache {} has been cleaned, event={}", CACHE_FOR_SOMETHING, event);
    }

}

如何公开参数名称或如何让 spring 分析原始类而不是代理?

【问题讨论】:

    标签: spring proxy aop spring-el spelevaluationexception


    【解决方案1】:

    我遇到了类似的问题,并通过使用 #root.event 而不是 #event 找到了解决方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-27
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多