【问题标题】:refer on bean.property in @Scheduled by SpEL参考 @Scheduled by SpEL 中的 bean.property
【发布时间】:2021-08-07 11:37:39
【问题描述】:

我将在@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?

我做错了什么?

【问题讨论】:

    标签: java spring configuration spring-annotations


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多