如何使用注释从属性文件中读取键 - 值对

时间:2016-05-04 08:44:32

标签: java spring

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

1 个答案:

答案 0 :(得分: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.

要获得更多帮助,您可以参考此Link Here

相关问题