spring - set an annotation attribute from an environment variable? -
i'm trying set annotation value environment variable:
@configuration @componentscan @enableautoconfiguration @enablescheduling class application { @scheduled(cron = "${db_cron}") def void schedule() { ... } public static void main(string... args) { springapplication.run(application, args) } ... }
however, following compile time error:
attribute 'cron' should have type 'java.lang.string'; found type 'java.lang.object' in @org.springframework.scheduling.annotation.scheduled
is possible set annotation way, or need use other technique such setting value in property file?
you can not use gstrings in java annotations in groovy. have use "proper" strings. e.g.
@scheduled(cron = '${db_cron}')
note single quotes here. if groovy sees $
in "
-quoted string, turn gstring. can not done java annotations , don't want here anyway, since want spring property set here. is, error message tries here, no basetype string used here object (the gstring).
Comments
Post a Comment