import java.util.Properties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
public class PropertiesUtil implements InitializingBean{
private static Properties loadProperties;
@Override
public void afterPropertiesSet() throws Exception {
Resource res = new ClassPathResource("system.properties");
loadProperties = PropertiesLoaderUtils.loadProperties(res);
}
public static String getValue(String key){
return loadProperties.getProperty(key);
}
}
springmvc.xml注册
<bean id="propertiesUtils" class="com.cloudjet.point.mgr.utils.PropertiesUtil"></bean>
使用:
String url = PropertiesUtil.getValue("url");