/**
* web层全局常量配置帮助类
*/
public class GlobalSetting {
private static final String FILE_NAME = "/global.properties";
private GlobalSetting(){}
private static Properties p;
static{
p = PropertiesHelper.load(FILE_NAME);
}
public static String get(String key){
return null==p?"":p.getProperty(key);
}
}
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;
public class PropertiesHelper {
public static Properties load(String fileName) {
try {
InputStream in = PropertiesHelper.class.getResourceAsStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
Properties p = new Properties();
p.load(br);
return p;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
public interface ConstantPool -- 常量池
public static final String QINIU_AK = "QINIU_AK";
配置文件:
#XX
QINIU_AK=XXXXXXX
使用获取配置文件:
GlobalSetting.get(ConstantPool.QINIU_AK);
-----
springboot 定时任务 另一种读配置文件
启动类 @EnableScheduling
定时任务类 上 @Component
配置文件的:moxie.carriers.contract.handler.task =59 * * * * *
方法上@Scheduled(cron = "${moxie.carriers.contract.handler.task}")
"---------
读取配置方式二:
@Component
@PropertySource(name="application.properties",value= {"classpath:application.properties"},ignoreResourceNotFound=false,encoding="UTF-8")
方法上 @Scheduled(cron ="${jobs.lawTime}" )
配置文件的:jobs.lawTime =59 * * * * *
读取配置文件的另一个方式(使用Properties) 可参考: http://blog.51cto.com/fluagen/409262
文章中若有不足之处,还望指出。坚持是一种精神,分享是一种快乐!