SpringMVC + FreeMarker 国际化使用方法
1、配置Spring
<!-- 国际化 -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>i18n</value>
</list>
</property>
</bean>
2、建立资源文件
图中使用了2组资源文件 i18n 与 messages,是为了测试命名规则,因为网上查资料看到有人讲Spring国际化需要命名为messages,结果这种说法完全错误。
文件前缀命名没有限制,只需要与第一步中的value值匹配即可。后缀则必须按规则来写messages_en_US.properties或i18n_en_US.properties。
3、项目中加入springmvc整合freemarker的国际化的支持文件spring.ftl,此文件在spring-webmvc的jar包中,以spring3.2为例: