Home > database >  How to use arithmetical operations i YML file?
How to use arithmetical operations i YML file?

Time:10-28

I'm using SpringBoot.

In previous projects I was using application.property file, and content looks look this:

seconds.timeOut=10
interval.milliseconds.cleaner=#{${seconds.timeOut}*2*1000}
interval.seconds.cleanerOffset=#{${seconds.timeOut}*3}

result was correct cleaner=20000 and cleanerOffset=30

In new project I switch to application.yml file. Have same configuration:

      seconds:
        timeOut: 10
      interval:
        milliseconds:
           cleaner: ${seconds.timeOut}*2*1000
      interval:
        seconds:
          cleanerOffset: ${seconds.timeOut}*3

but result is string cleaner = "10*2*1000" Of course I have exception:

Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'cleaningWorker': Invalid fixedDelayString value "10*2*1000" - cannot parse into long

I can't found any workaround could you help me?

CodePudding user response:

Try:

$(( ${seconds.timeOut} * 2000seconds ))

If this didn't work please refer to this, this will help.

CodePudding user response:

Thanks for all.

this solution for me:

      seconds:
        timeOut: 10
      interval:
        milliseconds:
           cleaner: '#{${seconds.timeOut}*2*1000}'
      interval:
        seconds:
          cleanerOffset: '#{${seconds.timeOut}*3}'
  • Related