Spring xml config enable @Async without @Scheduled

亡梦爱人 提交于 2019-12-10 21:22:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!