I have a @ConfigurationProperties class like this:
@ConfigurationProperties(prefix = "myprops", ignoreUnknownFields = false) @Configuration public class MyProperties { private Long mySchedulerRate; @Bean public Long mySchedulerRate() { return this.mySchedulerRate; } } I'm registering it as a bean so I can refer to it in an annotation for a Spring scheduler:
@Scheduled(fixedRateString = "#{@mySchedulerRate}") public void runScheduledUpdate() { ... { However, I now want to write a unit test where I want to be able to set a different value for the bean 'mySchedulerRate'. Mocking/Spying on the @ConfigurationProperties class doesnt seem to work since the scheduler gets set up before the stubbing has been set to return my desired value.
What is the easiest way to achieve what I am trying to do?