步骤:
1、创建properties文件(如:在WEB-INF/core_config/options.properties),里有option.global.sleep.time=1000 ;
2、在spring配置文件里加如下配置:
<bean id="messageSource" class="org.springframework.context.support .ReloadableResourceBundleMessageSource" scope="singleton"> <property name="basenames"> <set> <value>WEB-INF/core_config/options</value> </set> </property> </bean> |
3、增加ResourceUtil工具类:
import java.util.Locale; import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import com.leagle.util.SpringBeanUtil;
/** * 资源工具 */ public class ResourceUtil {
public static String getResourceString(String key) { ReloadableResourceBundleMessageSource messageSource = (ReloadableResourceBundleMessageSource) SpringBeanUtil .getBean("messageSource"); return messageSource.getMessage(key, null, Locale.getDefault()); } } |
4、取properties里的值:
ResourceUtil.getResourceString("option.global.sleep.time"); |