1

We have a properties file in which we mention to take the properties to be taken from JSON/Zookeeper.

Example:

AppName : SampleApp

Inside SampleApp.properties we will specify

configmode=json
jsonfile=/config.json

There are many examples how to assign the properties inside the @Scheduled annotation using properties file.

But in this scenario ,

we have to read the property using some Java class (say Name is Config) String cronExp=Config.get("CRONEXPRESSION") ; and put that cron inside @Scheduled(cron = cronExp) ..Is this possible?

Note we cannot move the CRONEXPRESSION propepty to property file directly..Inside properties file we mention json..inside code we read that json and pick the property from there..

svs teja
  • 957
  • 2
  • 22
  • 43
  • 1
    Check this: http://forum.spring.io/forum/spring-projects/container/75408-feature-scheduled-with-value-cron-expression – Julian L. Jan 22 '16 at 12:35

1 Answers1

0

Short answer:

saddly, you cannot do that.

In Java, annotation attributes are resolved at compile time. Which means that you can only provide an immediate value or a constant.

Use case specific answer:

Spring let's you use SpEL in a number of places. In this case, the value of the annotation's attribute is still resolved at compile time, but this value is evaluated by Spring at runtime. @RC provided a good link to a discussion of the details.

Somewhat longer answer:

It is possible to modify annotations at runtime by using reflection, but that's a tricky path, and the code processing the annotation need to handle the case where annotations change at runtime (this is very rarely the case).

Community
  • 1
  • 1
Guillaume
  • 18,494
  • 8
  • 53
  • 74