首页 > 解决方案 > 参考 @Scheduled by SpEL 中的 bean.property

问题描述

我将在@Scheduled 中动态设置“fixedRate”值。

为此,我正在尝试使用 SpEL 能力,如下所示:

  @AllArgsConstructor
  public class ContentSender {

   @Scheduled(fixedRateString = "#{OuterProperties.rateForMessageReading}")
      public void contentModelMessageSource() throws IOException {       
            }
     }

具有目标属性的类:

  @Getter
  @Setter
  @ConfigurationProperties("app")
  public class OuterProperties {
      private static final long WAITING_INTERVAL = 100;
      private long rateForMessageReading;
  }

结果在部署阶段我收到:

  SpelEvaluationException: EL1008E: Property or field 'outerProperties' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?

我究竟做错了什么?

标签: javaspringconfigurationspring-annotations

解决方案


问题是我只使用@ConfigurationProperties。当我添加@Configuration 问题就消失了。

@Getter
@Setter
@Configuration
@ConfigurationProperties("app")
public class OuterProperties {
     private static final long WAITING_INTERVAL = 100;
     private long rateForMessageReading;
}

推荐阅读