Spring的ApplicationContext加载Property文件

本文介绍了如何使用Spring的ApplicationContext加载Property文件,以实现国际化和动态加载功能。Spring提供了ResourceBundleMessageSource和ReloadableResourceBundleMessageSource两个工具,后者支持热加载和自定义编码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

利用Spring的ApplicationContext加载Property文件,可以实现国际化和'热'加载文件(不用重启应用).Spring提供了ResourceBundleMessageSource和ReloadableResourceBundleMessageSource两个类加载property文件,后者提供了'热'加载以及指定编码等功能.

例子:配置文件

<!--
        <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basenames"> <list> <value>resource/msg1</value>
        <value>resource/msg2</value> </list> </property> </bean>
    -->
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="defaultEncoding" value="gbk" />
        <property name="cacheSeconds" value="5" />
       
        <property name="basenames">
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值