在Form.java文件中检索用于国际化的Spring外部化字符串

在Form.java文件中检索用于国际化的Spring外部化字符串,java,spring,datetime,model-view-controller,internationalization,Java,Spring,Datetime,Model View Controller,Internationalization,我想知道,在表示层上,是否有类似于以下操作的方法来按区域设置检索message.properties文件中的外部化Spring消息。这是如何在视图上完成的: <spring:message code="ejournal.starttransaction"/> 从messages.properties文件检索这些硬编码的日期格式会很好,就像我的视图调用国际化文本一样 我很抱歉,如果这听起来像是一个非常幼稚或无知的问题,但环顾四周,似乎没有什么东西能与这个问题的主题完全相同。如果有人对

我想知道,在表示层上,是否有类似于以下操作的方法来按区域设置检索message.properties文件中的外部化Spring消息。这是如何在视图上完成的:

<spring:message code="ejournal.starttransaction"/>
从messages.properties文件检索这些硬编码的日期格式会很好,就像我的视图调用国际化文本一样

我很抱歉,如果这听起来像是一个非常幼稚或无知的问题,但环顾四周,似乎没有什么东西能与这个问题的主题完全相同。如果有人对如何做到这一点有建议,请让我知道或建议一些初学者阅读

如果您需要更多的代码片段,请告诉我

编辑-

消息源确实存在。现在尝试通过注释处理每个答案

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basenames">
      <list>
        <value>/WEB-INF/messages/message</value>
      </list>
    </property>
</bean>

/WEB-INF/messages/message
编辑2-


Spring版本是2.5.4。

在SpringMVC中,您可以如下配置ResourceBundleMessageSource

<bean name="messageSource" 
      class="org.springframework.context.support.ResourceBundleMessageSource" >
    <property name="basename" value="ScreenMessages" />
</bean>
@值注释仅在spring 3中可用。如果您使用的是Spring2.5,那么将ResourceBundleMessageSource注入到bean中

@Autowired
private ResourceBundleMessageSource messageSource;
现在,您可以使用locale检索以下属性

Locale locale = LocaleContextHolder.getLocale();
String dateFormat = messageSource.getMessage('ejournal.dateFormat',null,locale);

分别使用
DateFormat.getDateTimeInstance
DateFormat.getDateInstance
DateFormat.getTimeInstance
,它们返回当前
语言环境的格式,但也允许您传递
语言环境
是的,我相信它们在大多数情况下都会起作用,可能是最佳实践,但是我相信我们的要求不同于这些提供的“标准”语言环境。不过,我会尝试一下,看看它们是否符合我们的地区偏好,也许这会让那些认为这应该是另一种方式的人信服:)会尝试的,谢谢!我相信我们已经在项目中设置了messageSource,因为我们有message_fr_CA.properties等属性文件,但这不是我做的,所以我只是尝试导航应用程序和所有内容。我在message.properties文件中添加了以下内容,您可以在编辑中看到我问题中的消息源映射。ejournal.dateFormat=yyyy-MM-dd HH:MM:ss然后导入。。。导入org.springframework.beans.factory.annotation.Value;尝试了dateFormat上的代码片段,Eclipse建议进行一项更改,最终为我完成了导入(很可能是jar导入,也许我们正在使用旧的Spring版本?),dateFormat似乎没有设置为超过null,从而导致了一个空指针。建议还是需要更多信息?现在就找到Spring版本,如果有帮助的话。。。不过,必须导入SpringVersion才能检查这一点。编辑-Spring版本是2.5.4。Eclipse似乎要求导入Springbeans 3.1.2发行版jar。不确定这些版本是否相互独立,或者是否兼容。好的,在Spring2.5中该注释不可用。我将使用其他解决方案编辑邮件。
@Autowired
private ResourceBundleMessageSource messageSource;
Locale locale = LocaleContextHolder.getLocale();
String dateFormat = messageSource.getMessage('ejournal.dateFormat',null,locale);