如何在Spring中从文件读取参数到Schedule注释?

肾上腺素:

我在c:\ Temp文件夹中创建文件init.txt。

login=rtyhjmdsf
password=cxzxdrfks
fixrate=6000

如何在Spring中从文件中读取参数“ fixrate”到Schedule注释?如何在SpEL中将字符串转换为Long?

此限制不起作用(

@Component
@PropertySource("file:c:\temp\init.txt")
class CronSchedule {

@Scheduled(fixedRate = "#{Long(scheduler[fixrate])}" as Long)
fun publicImage() {
        println("I'm starting.")
}
}
Atul Kulkarni:

无需将其转换为long,而是可以使用fixedRateString。

@Scheduled(fixedRateString = "${fixrate}")

下面的代码在Java中有效

@Component
@PropertySource("file:/tmp/init.txt")
class CronSchedule {

    private static final Logger log = LoggerFactory.getLogger(CronSchedule.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRateString = "${fixrate}")
    public void reportCurrentTime() {
        log.info("The time is now {}", dateFormat.format(new Date()));
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Java中读取rar文件注释?

Jmeter-如何在参数文件中添加注释?

如何在Angular2中传递参数到楼上

如何从文件读取整数到数组

如何在cgo参数中编写注释

如何在Spring Boot中从资源读取JSON文件

如何在Spring Batch中同时读取2个文件

如何在python中打开文件,读取注释(“#”),在注释后找到一个单词并在其后选择单词?

在Spring框架中读取带注释的属性文件

如何在通过注释自动装配的Spring bean中传递类构造函数参数

如何在prototxt文件中写注释?

如何在Laravel中读取URL参数

如何在AngularJS中读取URL参数?

如何在Spring Boot中从目标文件夹中读取Java文件

如何在不使用连接参数的情况下从python中的.sql文件中读取数据

如何在Spring Boot 2.1.7中使用外部路径作为命令行参数或config文件夹读取外部xml

如何在Dropbox中获取计数到我的帐户中的文件和大小的列表?

如何在 C++ 中读取具有带参数值的 JSON 文件

如何在Cshell中读取并替换为两个参数文件?

使用Spring注释读取文件属性

如何在Node.JS中从HTML调用函数到Javascript文件

如何在Spring Webflux中读取存储在classpath资源中的JSON文件?

如何在spring boot中从属性文件中读取

如何在Go中读取文件属性

如何在App Engine中读取文件?

如何在R中读取rsav文件

如何在Android Assets中读取文件

如何在Elm中读取本地文件?

如何在 cat << EOF > 中读取文件