【问题标题】:Why when I use java.util.Random in SpEL there is a SpelEvaluationException?为什么当我在 SpEL 中使用 java.util.Random 时会出现 SpelEvaluationException?
【发布时间】:2017-03-12 10:56:10
【问题描述】:

beans.xml

<bean id="duke" class="Juggler">
    <constructor-arg value="#{T(java.util.Random).nextInt(10)}"/>
</bean>

例外:

原因:org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 20): Method call: Method nextInt(java.lang.Integer) can not be found on java.util.Random type

【问题讨论】:

  • nextInt(int) 不是静态方法。您需要java.util.Random 的实例才能调用nextInt(10)

标签: java spring-el spelevaluationexception


【解决方案1】:
"value=#{ new java.util.Random().ints(1, 0, 10).sum() }"

SpEL doc

【讨论】:

    【解决方案2】:

    可能这样你只能调用静态方法

    【讨论】:

      猜你喜欢
      • 2020-11-19
      • 2011-08-01
      • 1970-01-01
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多