spring 下得到properties中的配置文件
来源:互联网 发布:想买摔炮在淘宝怎么搜 编辑:程序博客网 时间:2024/06/05 19:56
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
public class SystemConfig {
private static Properties props = new Properties();
static{
try {
props.load(getLocation().getInputStream());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getValue(String key){
return props.getProperty(key);
}
public static void updateProperties(String key,String value) {
props.setProperty(key, value);
}
/*
* getServerName
* 获取当前服务器运行环境的名称,用来标示是在运行环境中的哪台服务器
*/
public static String getServerName(){
String serverName = getValue("server_name");
if(null!=serverName)
return serverName;
else
return "Unknown Server";
}
public static Resource getLocation() {
Resource location =null;
ApplicationContext context=new ClassPathXmlApplicationContext(new String[]{});
if(null==location){
location = context.getResource("classpath:PhotoConfig.properties");
}
return location;
}
public static Resource getResource(String fileName) {
ApplicationContext context=new ClassPathXmlApplicationContext(new String[]{});
return context.getResource("classpath:"+fileName);
}
public static void main(String[] args) {
System.out.println(SystemConfig.getValue("server_name"));
}
}
import java.io.IOException;
import java.util.Properties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
public class SystemConfig {
private static Properties props = new Properties();
static{
try {
props.load(getLocation().getInputStream());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getValue(String key){
return props.getProperty(key);
}
public static void updateProperties(String key,String value) {
props.setProperty(key, value);
}
/*
* getServerName
* 获取当前服务器运行环境的名称,用来标示是在运行环境中的哪台服务器
*/
public static String getServerName(){
String serverName = getValue("server_name");
if(null!=serverName)
return serverName;
else
return "Unknown Server";
}
public static Resource getLocation() {
Resource location =null;
ApplicationContext context=new ClassPathXmlApplicationContext(new String[]{});
if(null==location){
location = context.getResource("classpath:PhotoConfig.properties");
}
return location;
}
public static Resource getResource(String fileName) {
ApplicationContext context=new ClassPathXmlApplicationContext(new String[]{});
return context.getResource("classpath:"+fileName);
}
public static void main(String[] args) {
System.out.println(SystemConfig.getValue("server_name"));
}
}
0 0
- spring 下得到properties中的配置文件
- properties在spring配置文件中的用法
- 得到CDA properties 的配置文件
- spring .properties 配置文件
- Spring 使用Properties配置文件
- spring 读取properties配置文件
- spring加载properties配置文件
- spring 配置文件datasource.properties
- spring 配置文件引入properties
- Spring读取properties配置文件
- spring配置文件获取其他properties文件中的值及使用
- spring的xml配置文件读取properties文件中的属性
- Java中的properties配置文件
- Spring 使用Properties配置文件(一)
- Spring 使用Properties配置文件(二)
- Spring PropertyPlaceholderConfigurer初始化properties配置文件
- Spring读取自定义properties配置文件
- spring加载外部properties配置文件
- 线程安全
- 显示Android系统桌面
- 中国历史文化名镇(村)名单。178个镇(村)榜上有名,其间河北省武安市伯延镇等71个镇为中国历史文化名镇、北京市房山区南窖乡水峪村等107个村
- STM32F103VCT6+W5500实现TCP Client通信
- ExtJs4案例学习笔记(一)
- spring 下得到properties中的配置文件
- 发布android应用程序
- Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
- 网页代理
- 使用XmlReader类读取XML数据之
- ubuntu下Pureftpd配置之匿名登录功能
- C++ 使用备注
- 简单服务器。
- linux常用默认文件&默认路径