【问题标题】:Spring ReloadableResourceBundleMessageSource: Seeing UnknownFormatConversionExceptionSpring ReloadableResourceBundleMessageSource:看到 UnknownFormatConversionException
【发布时间】:2013-10-17 18:27:13
【问题描述】:

我通过 Spring 配置了 ReloadableResourceBundleMessageSource。一切正常。我正在尝试在资源包中添加更多字符串,但是,我看到了 UnknownFormatConversionException。

我希望输出为:
Following filesystems are below threshold level (25%):/db

我的资源包有
filesystemsBelowThreshold=Following filesystems are below threshold level {0}%:{1}

但是,上述格式不起作用,它会抱怨
UnknownFormatConversionException: Conversion = ')'.
如果我删除圆括号,它会抱怨
UnknownFormatConversionException: Conversion = ':'.
我尝试用另一个 % 转义 %,如
filesystemsBelowThreshold=Following filesystems are below threshold level {0}%%:{1},但是,我得到 UnknownFormatConversionException: Conversion = ':'.

知道如何解决这个问题吗?

【问题讨论】:

  • 我认为 = 和 : 是属性文件中的特殊字符
  • @SRT_KP:那行不通。我改成filesystemsBelowThreshold=Following filesystems are below threshold level {0}%\:{1},但是还是出现同样的错误,即UnknownFormatConversionException: Conversion = ':'

标签: java spring internationalization


【解决方案1】:

这里是代码

<bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>

还有属性文件

filesystemsBelowThreshold=Following filesystems are below threshold level {0}%:{1}

还有测试

        Object[] obj = {25, "/db"};
        String str= message.getMessage("filesystemsBelowThreshold", obj, null);
        System.out.println(str);

还有输出

以下文件系统低于阈值水平 25%:/db

【讨论】:

    猜你喜欢
    • 2012-02-20
    • 2012-10-08
    • 2013-12-08
    • 2012-04-27
    • 1970-01-01
    • 2012-08-27
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    相关资源
    最近更新 更多