The following bean definition:
<bean id="client" factory-bean="builder"
factory-method="withConfiguration">
<constructor-arg type="java.lang.String"
value="#{ ${domain} == 'prod' ?
Base.${domain}.${realm}.rpt : Base.${domain}.${realm}}" />
fails with the following error:
org.springframework.web.context.ContextLoader: Context initialization failed { org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'test' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
${domain} should evaluate to 'test'. What is wrong with the configuration?
your property-placeholder result has to be wrapped to literal
, if you are going to test it against another literal and don't use it as a property as you in the rest of your expression:
value="#{ '${domain}' == 'prod' ?
'Base.${domain}.${realm}.rpt' : 'Base.${domain}.${realm}'}"
I've accepted your edit. Thanks.
The property-placeholder works before SpEL, so, any property-placeholder result becomes some SpEL part and it really has to be valid one.
I understand the first part '${domain}' == 'prod'
, when you really must have a literal for the PP result to compare it with another literal. The rest of your SpEL hasn't been clear for me from the beginning, but now I see that it should be a String
too for ctor arg.
Otherwise SpEL tries to treat test
as some evaluation context property, that we see in the exception.
Try to imagine your SpEL without property-placeholders.
Because I did not add in the missing apostrophes:
th:if = "${user.name} == null";
The correct way is:
th:if = "'${user.name}' == null";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With