Property Valuation Inside Spring Expression Lang (SpEL)

Our service has a process that is scheduled according to the properties file by reading the refreshIntervalMillis property. Its value is entered directly into the Quartz trigger with this configuration:

<bean name="trigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean " p:repeatInterval="${refreshIntervalMillis}"> ... </bean> 

However, the administrators who install this service think about the hours / days, so to simplify them, we changed this to:

  • Renamed refreshIntervalMillis to refreshIntervalMinutes
  • Changed for the code above:
  p: repeatInterval = "# {1000 * 60 * T (java.lang.Integer) .valueOf (@configurationProperties ['garbageLevelWatcher.refreshIntervalMinutes'])}"

Note. The property object appears as a bean named "configurationProperties"

Is there a simpler syntax to achieve the same?

Thanks,

+4
source share
2 answers

"#{T(java.util.concurrent.TimeUnit).MINUTES.toMillis( @configurationProperties['garbageLevelWatcher.refreshIntervalMinutes'])}"

EDIT:

Or...

 <context:property-placeholder properties-ref="configurationProperties" <util:constant id = "MINUTES" static-field="java.util.concurrent.TimeUnit.MINUTES" /> 

and

 "#{@MINUTES.toMillis(${garbageLevelWatcher.refreshIntervalMinutes})}" 
+7
source

If properties are viewed using PropertyPlaceholderConfigurer, @PropertySource or <context: property-placeholder /> and the context knows about it

You can write it like this:

 p:repeatInterval="#{ 1000 * 60 * T(java.lang.Integer).valueOf('${garbageLevelWatcher.refreshIntervalMinutes}') }" 
+1
source

All Articles