1
votes

I am using spring boot 2.2.6 and as documentation says:

When the @ConfigurationProperties bean is registered using configuration property scanning or via @EnableConfigurationProperties, the bean has a conventional name: -, where is the environment key prefix specified in the @ConfigurationProperties annotation and is the fully qualified name of the bean. If the annotation does not provide any prefix, only the fully qualified name of the bean is used.

The bean name in the example above is acme-com.example.AcmeProperties.

However when I use this SpEL: @Scheduled(fixedDelayString = "#{@(mr-my.config.properties.ApplicationProperties).task.get(T(my.config.Constants).CONST).delay}") I am getting an error:

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.
2

2 Answers

1
votes
@Scheduled(fixedDelayString = "#{@(mr-my.config.properties.ApplicationProperties).task.get(T(my.config.Constants).CONST).delay}")

@ means you need to provide a bean with the given name.

@Configuration
class SchedulerConfig{

 @Bean
  public String scheduler1Delay() {
     return "500000s";
  }
}

Now set the bean name in the configuration as

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

The prefix supplied to the ConfiguiartionProperties annotation is the name of the bean.

For example:

package com.my.company;

...

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

    private Duration theInterval = Duration.ofSeconds(30);

    // getter and setter
}

and then

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