[英]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.