0

I have a Spring Boot (2.1.3) project using the Quartz scheduler. It is included via the starter:

dependencies {
    ...
    implementation('org.springframework.boot:spring-boot-starter-quartz')
}

The application is (mainly) configured with component scanning. If I run the application everything is fine. If I run a test annotated with @SprinBootTest everything is fine, too. But if I use this custom annotation

@DataJpaTest
@ComponentScan(basePackages = ["com.mycompany"])
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
@ActiveProfiles("intTest")
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Inherited
annotation class JpaTest

instead of @SpringBootTest I get a NoSuchBeanDefinitionException because no Quartz Scheduler could be found.

I've tried to add the Quartz package to the component scan, but that doesn't help:

@ComponentScan(basePackages = ["com.mycompany", "org.quartz"])

How can make Spring to pick up the Scheduler with my test setup with my custom configuration annotation?

deamon
  • 89,107
  • 111
  • 320
  • 448
  • An `@ComponentScan` here is useless as it will be ignored. Also this isn't a valid annotation, as that should have something as `public @interface JpaTest`. – M. Deinum Apr 26 '19 at 07:12

2 Answers2

0

I assume your SpringBoot app declares @EnableScheduling somewhere. Try add it to your @JpaTest

Alexander Pavlov
  • 2,264
  • 18
  • 25
0

I've no idea how to fix the component scanning itself, but a workaround is to register the Scheduler explicitly in code:

@Configuration
class SchedulerConfiguration {

    @Bean
    fun scheduler(): Scheduler = StdSchedulerFactory.getDefaultScheduler()
}
deamon
  • 89,107
  • 111
  • 320
  • 448