【问题标题】:Is it possible to populate spring util:list via properties file?是否可以通过属性文件填充 spring util:list?
【发布时间】:2013-12-31 13:15:03
【问题描述】:

我想通过属性文件填充传输端点。我试过了,但是没有用

<util:properties id="cxfProperties" location="/WEB-INF/classes/cxf.properties" />

<util:list id="transportEndpoints">
    <!--
    <value>http://localhost:8080/doubleit/services/doubleit.*</value>
    -->
    <value>#{cxfProperties.service.wsdllocation}</value>
</util:list>

在我的属性文件中

service.wsdllocation=http://localhost:8080/doubleit/services/doubleit.*

我得到错误:

表达式解析失败;嵌套异常是 org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 14): 找不到字段或属性“服务” “java.util.Properties”类型的对象

【问题讨论】:

    标签: spring properties spring-el spelevaluationexception


    【解决方案1】:

    我不认为 SpEL 为 Properties 中的属性提供直接字段访问语法。所以我认为正确的语法应该是:

    #{cxfProperties.getProperty('service.wsdllocation')}
    

    #{cxfProperties.getProperty('service.wsdllocation', 'SOME_DEFAULT_VAL')}
    

    【讨论】:

    • 我收到以下错误:表达式解析失败;嵌套异常是 org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 14): Field or property 'service' cannot be found on object of type 'java.util.Properties'
    • 您确定您使用的是我提供的新表达式吗?因为在我的表达中,service 的字段/属性不再导航,这与您的错误消息相矛盾。您可能只是使用了旧的表达方式。
    • 刚刚创建了一个测试项目,我的建议按预期工作。
    猜你喜欢
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多