【问题标题】:occur "Could not resolve placeholder KName" exception when start a webApp启动 webApp 时发生“无法解析占位符 KName”异常
【发布时间】:2012-06-05 12:41:05
【问题描述】:

这里有一篇关于 Spring 的博客: http://blog.springsource.org/2011/02/15/spring-3-1-m1-unified-property-management/

它引入了一个新功能:导入标签中的用户占位符。 例如:<import resource="com/bank/service/${customer}-config.xml"/>

嗯,我也是 3.1。

然后,当我启动 MYAPP 时,奇迹并没有发生..

这是我的代码: (sourceFolder 中的 config.properties):

kName = P0765

(春天的 xml):

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">;
    <property name="location" value="classpath:config.properties" >;
</bean>

<import resource="readyData/${KName}.xml"/>

:( 什么工作没做?

【问题讨论】:

  • 属性区分大小写。 ${KName}.xml 中的“K”字符为大写,config.properties 中的“k”字符为小写。

标签: java spring placeholder


【解决方案1】:

在 import 元素中解析的属性必须设置为 JVM 系统属性或系统环境变量。您在此处链接的博客文章中对此进行了描述。 这是因为合并 Spring 配置文件发生在初始化 bean(PropertyPlaceholderConfigurer 是一个 bean)之前,它可能不会改变,请参阅这个被拒绝的功能请求https://jira.springsource.org/browse/SPR-1358

【讨论】:

    猜你喜欢
    • 2021-06-23
    • 2018-06-13
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    相关资源
    最近更新 更多