How to disable scheduling for a spring boot test

Posted by Java developer blog on August 22, 2018

Add a separate configuration class with @Profile(!test), @EnableScheduling annotations

1
2
3
4
@Profile(!test)
@Configuration
@EnableScheduling
public static class SpringConfiguration {}

Then either add the following line below in the test application.properties file to disable the spring scheduling for the test profile

1
spring.profiles.active=test

or add the following annotation @ActiveProfiles to a test class

1
@ActiveProfiles("test")