Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在类型为';的对象上找不到字段或属性;org.springframework.beans.factory.config.beanextressioncontext_Java_Spring_Spring El - Fatal编程技术网

Java 在类型为';的对象上找不到字段或属性;org.springframework.beans.factory.config.beanextressioncontext

Java 在类型为';的对象上找不到字段或属性;org.springframework.beans.factory.config.beanextressioncontext,java,spring,spring-el,Java,Spring,Spring El,以下bean定义: <bean id="client" factory-bean="builder" factory-method="withConfiguration"> <constructor-arg type="java.lang.String" value="#{ ${domain} == 'prod' ? Base.${domain}.${realm}.rpt : Base.${domain}.${r

以下bean定义:

<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}}" />

失败,出现以下错误:

org.springframework.web.context.ContextLoader:上下文初始化失败{org.springframework.beans.factory.BeanExpressionException:表达式解析失败;嵌套异常为org.springframework.Expression.spel.SpelEvaluationException:EL1008E:(位置0):在“org.springframework.beans.factory.config.BeanExpressionContext”类型的对象上找不到字段或属性“test”

${domain}应计算为“test”。
配置有什么问题?

如果要针对另一个文本测试属性占位符结果,并且在表达式的其余部分中不将其用作属性,则必须将属性占位符结果包装为
literal

value="#{ '${domain}' == 'prod' ? 
            'Base.${domain}.${realm}.rpt' : 'Base.${domain}.${realm}'}"
我接受了你的编辑。谢谢

属性占位符在SpEL之前工作,因此,任何属性占位符结果都会成为SpEL的一部分,并且必须是有效的部分

我理解第一部分
'${domain}'=='prod'
,当您确实必须有一个文本才能将PP结果与另一个文本进行比较时。SpEL的其余部分从一开始我就不清楚,但现在我看到,对于ctor arg,它也应该是一个
字符串

否则,SpEL会尝试将
test
视为我们在异常中看到的某种计算上下文属性


尝试想象没有属性占位符的SpEL。

因为我没有添加缺少的撇号:

th:if = "${user.name} == null";
正确的方法是:

th:if = "'${user.name}' == null";
对于布尔字段,请使用如下所示的“”

${'offer.isActive'}

抱歉,无法理解您的意思:“并且不要在表达式的其余部分将其用作属性”。我需要此功能:
如果域的值为“prod”,则使用“Base.prod.US.rpt”作为构造函数参数,否则使用“Base.test.US”作为参数
。请注意
${realm}
对我们进行了评估。我对答案进行了编辑,使其完全正确。js但我不理解该特定部分。这看起来应该是对不同问题答案的注释。