Spring: Apply Annotation based on properties -
say using @scheduled annotation on function. want annotation take effect if property defined in properties file. how configure scenario? use case: same app deployed on multiple servers @scheduled should active on 1 server.
my idea:
- use bean (myscheduler), contains nothing more method annotated @schedule. method "forward" invocation real service.
- then annotate myscheduler class @component , @profile
- the use properties file enable or disable profile
sketch:
@component @profile("ontheserver") public class myscheduler{ @autowire private realservice realservice; @schedule(cron="1****") { realservice.dosomething(); } }
- @see: spring 3.1 m1: introducing @profile
- @see: @profile java doc
Comments
Post a Comment