简体   繁体   English

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

[英]How to read Key - value pair from property file using annotations

How to read this (fixedRate = 12000) 12000 form property file in 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.............");
}

You can add your properties file to the folder where your classes are exists. 您可以将属性文件添加到classes所在的文件夹中。 and then try this code. 然后尝试此代码。

 @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.

For more assistence you can refer this Link Here 为了获得更多的坚持,您可以在这里参考此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM