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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With