问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/20125454/spring-xml-config-enable-async-without-scheduled