簡體   English   中英

如何使用注釋從屬性文件中讀取鍵值對

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM