Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Field or property cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext

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?

like image 465
Aman Deep Gautam Avatar asked Aug 31 '14 16:08

Aman Deep Gautam


2 Answers

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.

like image 176
Artem Bilan Avatar answered Sep 24 '22 10:09

Artem Bilan


Because I did not add in the missing apostrophes:

th:if = "${user.name} == null";

The correct way is:

th:if = "'${user.name}' == null";
like image 34
jalon Avatar answered Sep 26 '22 10:09

jalon