如何为spring Web流定义自定义消息源?

Jan*_*omä 9 spring internationalization spring-webflow

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

国际化消息在Spring MessageSource访问的消息包中定义.要创建特定于流的消息包,只需在流的目录中定义messages.properties文件即可.为您需要支持的每个其他区域设置创建默认的messages.properties文件和.properties文件.

在我们的webapp中,我们使用Spring Webflow和专有框架.我们将所有国际化消息都放在一个文件中,我们希望Spring Webflow可以访问这个消息,而不是使用几十个属性文件乱丢我们的项目.有没有办法为spring webflow配置消息源,还是我们坚持使用messages.properties?

Sco*_*t A 6

在您的应用程序上下文XML文件中添加这样的内容:

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename"><value>classpath:yourSharedResourceBundle</value></property>
</bean>
Run Code Online (Sandbox Code Playgroud)

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