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();    }  } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -