Skip to content

Spel not supported on spring annotation @Scheduled.fixedDelayString [SPR-14137] #18709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Apr 8, 2016 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Apr 8, 2016

Sidi Amine Bouhamidi opened SPR-14137 and commented

I want to configure the 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 it throw this exception

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 resloved but the expression was not resloved.

I tried to configure 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 don't find the way to inject my custom CustomValueResolver.

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


Issue Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants