Exceptions: Caused by: org.springfram" /> Exceptions: Caused by: org.springfram" /> Exceptions: Caused by: org.springfram"/>

Why when I use java.util.Random in SpEL there is a SpelEvaluationException?

1.2k views Asked by At

beans.xml

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

Exceptions:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 20): Method call: Method nextInt(java.lang.Integer) cannot be found on java.util.Random type

2

There are 2 answers

0
rustot On

Probably such way you can call only static methods

0
Allenaz On
"value=#{ new java.util.Random().ints(1, 0, 10).sum() }"

SpEL doc