Reputation: 3395
Using Spring's xml configuration, how can I enable scanning of @Async
annotations without also enabling scanning of @Scheduled
annotations?
Normally, you would enable both simultaneously using <task:annotation-driven />
but I'm trying to enable scheduling only when a particular Spring profile is active.
Using Spring JavaConfig, you can use @EnableAsync
and @EnableScheduling
separately. I'm maintaining a project that's been around for a few years and uses only xml and annotation based config and I don't want to add JavaConfig to the mix unless it's the only way to do this.
Upvotes: 3
Views: 3262
Reputation: 124536
Instead of using the namespace add the respective beans manually. The org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor
takes care of @Async
and org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
takes care of @Scheduled
.
By registering the beans manually you can simply move the ScheduledAnnotationBeanPostProcessor
to the profile where you want it active.
Upvotes: 3