Java 如何在SpringBoot2.2.*中将@ConfigurationProperties bean自动连接到SpEL表达式中?

Java 如何在SpringBoot2.2.*中将@ConfigurationProperties bean自动连接到SpEL表达式中?,java,spring,spring-boot,Java,Spring,Spring Boot,我使用的是spring boot 2.2.6,如图所示: 当使用配置属性扫描或通过@EnableConfigurationProperties注册@ConfigurationProperties bean时,该bean有一个常规名称:-,其中是@ConfigurationProperties注释中指定的环境密钥前缀,是该bean的完全限定名。如果注释不提供任何前缀,则只使用bean的完全限定名 上面示例中的bean名称是acme-com.example.AcmeProperties 但是,当我使

我使用的是spring boot 2.2.6,如图所示:

当使用配置属性扫描或通过@EnableConfigurationProperties注册@ConfigurationProperties bean时,该bean有一个常规名称:-,其中是@ConfigurationProperties注释中指定的环境密钥前缀,是该bean的完全限定名。如果注释不提供任何前缀,则只使用bean的完全限定名

上面示例中的bean名称是acme-com.example.AcmeProperties

但是,当我使用此SpEL:
@Scheduled(fixeddedlaystring=“#{@(mr my.config.properties.ApplicationProperties).task.get(T(my.config.Constants.CONST).delay}”)
我收到一个错误:

Parameter 0 of constructor in my.controllers.Controller required a bean named 'mr' that could not be found.


Action:

Consider defining a bean named 'mr' in your configuration.
@
表示需要提供具有给定名称的bean

@Configuration
class SchedulerConfig{

 @Bean
  public String scheduler1Delay() {
     return "500000s";
  }
}
现在将配置中的bean名称设置为

@Scheduled(fixedDelayString = "#{@scheduler1Delay}")

提供给ConfiguiartionProperties注释的前缀是bean的名称

例如:

package com.my.company;

...

@ConfigurationProperties("alpha.beta.gamma")
public class TheTimes {

    private Duration theInterval = Duration.ofSeconds(30);

    // getter and setter
}
然后

@Scheduled(fixedDelayString = "#{@'alpha.beta.gamma-com.my.company.TheTimes'.theInterval}")
@Scheduled(fixedDelayString = "#{@'alpha.beta.gamma-com.my.company.TheTimes'.theInterval}")