java - 从 application.properties : Attribute value must be constant 读取

标签 java spring-boot

在下面给出的代码中,我得到了编译错误Attribute value must be constant。如何处理?

@Component
public class ScheduledTasks {

    @Value("${example}")
    String message;

    @Value("${update.rate}")
    final static long rate;

    @Scheduled(fixedRate = this.rate)
    public void update()
    {
        System.out.println(this.message);
    }
}

最佳答案

更改为:

@Scheduled(fixedRateString = "${update.rate}")
public void update()
{
    System.out.println(this.message);
}

关于java - 从 application.properties : Attribute value must be constant 读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39013894/

相关文章:

java - &amp 在 Java 中做什么?

java - 'gradle -q task' 实际上是做什么的?

java - @Async 执行时如何让调用者方法等待?

spring - 'org.springframework.boot.autoconfigure.web.HttpMapperProperties' 类被标记为已弃用?

java - 访问用户上的 LAZY 集合时出现 LazyInitializationException

Java - 在 KeyStore 中存储 key 对

java - 无法将 ArrayList<Impl> 传递给采用 ArrayList<Interface> 的方法

java - 在 JavaFX 中显示 pdf

spring-boot - 为 Controller 中的参数添加自定义验证注释 - JSR-303

spring - 如何在 undertow 中配置 Spring boot 2.4 服务器线程?