xatuljt 2016-07-06 12:55 采纳率: 0%
浏览 1147

property-placeholder 怎么作用于MessageSource?

目前是通过

<context:property-placeholder location="classpath:global.properties" />

的方式多环境打包,global.properties 文件中主要配置了数据库密码以及URL前缀等,但是我希望在

<bean name="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="cacheSeconds" value="5" />
    <property name="basenames">
        <list>
            <value>/WEB-INF/conf/system</value>
            <value>/WEB-INF/conf/url</value>
        </list>
    </property>
</bean>

中的property内也能使用被 property-placeholder 的设置格式化,请问大神们,该如何处理?非常感谢

  • 写回答

1条回答 默认 最新

  • xatuljt 2016-07-06 13:02
    关注

    global.properties 里面格式大致有

    app.name=app
    
    app.base=http://127.0.0.1:8080/app-web/
    app.static=http://127.0.0.1/app/
    
    

    我希望在 /WEB-INF/conf/url 地址配置里面如下方式使用

    web.index.url=${app.base}home/index.action
    web.login.url=${app.base}user/login.action
    
    web.static.url=${app.static}lib/js/
    
    

    但是目前不生效,查看了org.springframework.context.support.ReloadableResourceBundleMessageSource类的resolveCode(String code, Locale locale)方法

    /**
     * Resolves the given message code as key in the retrieved bundle files,
     * using a cached MessageFormat instance per message code.
     */
    @Override
    protected MessageFormat resolveCode(String code, Locale locale) {
        if (this.cacheMillis < 0) {
            PropertiesHolder propHolder = getMergedProperties(locale);
            MessageFormat result = propHolder.getMessageFormat(code, locale);
            if (result != null) {
                return result;
            }
        }
        else {
            for (String basename : this.basenames) {
                List<String> filenames = calculateAllFilenames(basename, locale);
                for (String filename : filenames) {
                    PropertiesHolder propHolder = getProperties(filename);
                    MessageFormat result = propHolder.getMessageFormat(code, locale);
                    if (result != null) {
    
                        // 这里没有格式化
                        return result;
                    }
                }
            }
        }
        return null;
    }
    
    

    这个是不是无法实现,或者我希望在Java代码中,如何取到的实体,手动处理?

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决