Reputation: 51
I have a class with configuration properties:
@Data
@ConfigurationProperties("message-starter")
public class JobProperties {
public Duration kafkaSendingPeriod;
public Duration rabbitSendingPeriod;
}
And class that aggregates this properties and uses them in @Scheduled annotation using Spring expression language:
@Component
@EnableConfigurationProperties(JobProperties.class)
@RequiredArgsConstructor
public class Job {
public final JobProperties jobProperties;
@Scheduled(fixedRateString="#{@jobProperties.getKafkaSendingPeriod()}")
public void fun(){
System.out.println("Time: " + LocalDateTime.now());
}
}
But when I run it I get the following exception:
Description:
A component required a bean named 'jobProperties' that could not be found.
Action:
Consider defining a bean named 'jobProperties' in your configuration.
Please tell me how to fix this exception so that I can get the value of the fields of the JobProperties class?
Upvotes: 0
Views: 284