[英]How to read Key - value pair from property file using annotations
如何在Spring中读取此内容(fixedRate = 12000)12000表单属性文件。
@Scheduled(fixedRate=120000)
public void tlogZipping() throws MposWSException {
LOGGER.info("Started tlog Zipping Job............. {}" + new Date());
try {
//......................
} catch (Exception e) {
LOGGER.error("FAIL TO CREATE RECEIPT ZIP FILE: {}",e);
throw new MposWSException(MposWSErrorCodes.FAIL_TO_CREATE_RECEIPT_ZIP_FILE, e);
}
LOGGER.info("Stopped tlog Zipping Job.............");
}
您可以将属性文件添加到classes
所在的文件夹中。 然后尝试此代码。
@PropertySource("classpath:config.properties") //set your Properties file source.
public class YourClass{
//1.2.3.4
@Value("${TLOG_ZIPPING_TIME_INTERVEL_IN_MINUTES }") //read your Property Key
private String IntervalTimeInMin; //Store in this Variable.
//hello
@Value("${anotherProperty}") //readd another Property Key
private String anotherProperty; //Store in this Variable.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.