Spel not supported in spring annotation @ Scheduled.fixedDelayString

I want to set fixedDelay in seconds in my properties file, then I want to convert it to millis in @Scheduled Annotation.

I expected this to work:

@Scheduled(fixedDelayString = "#{${my.scheduler.fixed.delay} * 1000}") 

but this exception excludes

 Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'myMethod': Invalid fixedDelayString value "#{5 * 1000}" - cannot parse into integer at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:384) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor$1.doWith(ScheduledAnnotationBeanPostProcessor.java:227) ~[spring-context-4.1.6.RELEASE.jar:4.1.6.RELEASE] 

$ {my.scheduler.fixed.delay} was correctly modified, but the expression was not replaced.

I tried setting my own StringValueResolver

 private static class CustomValueResolver implements StringValueResolver { private final ConfigurableBeanFactory beanFactory; private final ExpressionParser expressionParser; public CustomValueResolver(final ConfigurableBeanFactory beanFactory, final ExpressionParser expressionParser) { this.beanFactory = beanFactory; this.expressionParser = expressionParser; } @Override public String resolveStringValue( final String strVal) { String value = this.beanFactory.resolveEmbeddedValue(strVal); if (value.startsWith("#{")) { value = this.expressionParser.parseExpression(value).getValue(String.class); } return value; } } 

But I do not find a way to contribute my custom CustomValueResolver.

Am I on the right or wrong path? there is another easy way

+7
java spring spring-annotations spring-el
source share

No one has answered this question yet.

See related questions:

1873
What is the difference between @Component, @Repository and @Service annotations in Spring?
1492
Does Java support default parameter values?
904
Which @NotNull Java annotation should I use?
708
How to configure port for Spring Boot application
562
What is the Spring Framework designed for?
237
Spring MVC @PathVariable with dot (.) Truncated
one
Nested Mongodba problems with spring
0
Using JpaRepository with Spring and Hibernate Data
0
Spring 3 bob cannot be initialized in jboss 7 which uses ResourceBundleMessageSource
0
Error starting Spring-boot, I think some missing dependencies

All Articles