2016-05-04 56 views
0

如何在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............."); 
} 
+0

沒有這樣的文件,我能怎麼看你的代碼? @Dipesh –

+0

我的文件名是MyProperty.properties,它包含:TLOG_ZIPPING_TIME_INTERVEL_IN_MINUTES = 1200000 –

+0

這是一個註釋,比如'@ TLOG_ZIPPING_TIME_INTERVEL_IN_MINUTES'或簡單的按鍵,比如'TLOG_ZIPPING_TIME_INTERVEL_IN_MINUTES' –

回答

0

您可以將您的屬性文件添加到您的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. 

更多assistence你可以參考這個Link Here

+0

感謝Vikrant,但如果它是好的,我們可以用類中的任何整數值改變@Scheduled(fixedRate = 120000)這個「120000」。所以我可以在構造函數中初始化這個int值。 –

相關問題