如何为Spring Web流定义自定义消息源? [英] How can I define a custom message source for a spring web flow?

查看:56
本文介绍了如何为Spring Web流定义自定义消息源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

spring webflow文档提到,他们向流添加消息的方式是在流内部的messages.properties文件中定义与该流有关的所有消息:

The spring webflow documentation mentions that their way of adding messages to a flow is to define all messages regarding that flow in a file messages.properties inside the flow:

国际化消息是在Spring MessageSource访问的消息束中定义的.要创建特定于流的消息束,只需在流的目录中定义messages.properties文件.为您需要支持的每个其他语言环境创建一个默认的messages.properties文件和一个.properties文件.

Internationalized messages are defined in message bundles accessed by a Spring MessageSource. To create a flow-specific message bundle, simply define messages.properties file(s) in your flow's directory. Create a default messages.properties file and a .properties file for each additional Locale you need to support.

在我们的Web应用程序中,我们结合使用了Spring Webflow和专有框架.我们将所有国际化的消息保存在一个文件中,我们希望Spring Webflow可以访问此消息,而不是用数十个属性文件来填充我们的项目.有没有一种方法可以为Spring Webflow配置消息源,还是我们只能停留在messages.properties上?

In our webapp we use a mix of Spring Webflow and proprietary frameworks. We have all our internationalized messages in a single file and we'd like to have Spring Webflow access this one instead of littering our project with dozens of properties files. Is there a way to configure the message source for a spring webflow or are we stuck to messages.properties?

推荐答案

在您的应用程序上下文XML文件中放置以下内容:

Put something like this in your application context XML file:

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename"><value>classpath:yourSharedResourceBundle</value></property>
</bean>

只要文件位于类路径中,就应该使用它.

As long as the file is located on the classpath it should be used.

这篇关于如何为Spring Web流定义自定义消息源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆