Skip to content
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

Support SpEL next to placeholders in annotation attributes (e.g. @Scheduled) [SPR-13625] #18203

Closed
spring-projects-issues opened this issue Oct 30, 2015 · 4 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 30, 2015

Joseph Dawson opened SPR-13625 and commented

Currently The @Scheduled (fixdRateString) annotation supports property evaluations, however it does not parse spring expressions correctly.

The problem has been recreated at https://github.com/rikitikitaco/schedulerSpel


Reference URL: https://github.com/rikitikitaco/schedulerSpel

Issue Links:

Referenced from: commits ea4a766

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 30, 2015

Juergen Hoeller commented

This is actually by design, since SpEL expressions are semantically meant to be re-evaluated every time, whereas simple placeholder variables are semantically resolved once only - against the current values at startup. Scheduling requires a pre-defined trigger and is therefore semantically a match for placeholders but not really for fully dynamic SpEL expressions.

Do you have a specific use case? Could you use ApplicationContext environment properties or local PropertyPlaceholderConfigurer properties instead?

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Oct 30, 2015

Neil Green commented

It's not completely clear to me what "re-evaluated every time" means in this context. I understand that, for instance, in a Spring Integration application, using SpEL to make a routing decision we would want the expression to be evaluated each time a routing decision is made, but I don't think that applies here, it's simply extracting a value from the application context at startup.

There are other Spring annotations that support SpEL in the way described, e.g. org.springframework.amqp.rabbit.annotation.RabbitListener's queues field is resolved for both placeholders and full SpEL expressions in RabbitListenerAnnotationBeanPostProcessor. It would be good if we could replicate that behaviour in the @Scheduled annotation. I appreciate that if the value that the expression evaluates to changes, this wouldn't trigger a change in the configured schedule, but I think that's reasonable behaviour. If an developer wants to update the schedule after it's started, then using @Scheduled is probably not the way to do it anyway.

Would it be worth submitting a merge request for consideration?

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 2, 2015

Juergen Hoeller commented

Alright, we'll have a broader look at this (also including @JmsListener and co) for 4.3. We may support SpEL in such places as well; it's just not something we commonly do yet if the semantic context is startup-time resolution of static property values.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 17, 2016

Juergen Hoeller commented

As of 4.3, all EmbeddedValueResolverAware beans will receive a resolver adapter which deals with placeholders as well as expressions. In some other places, an EmbeddedValueResolver is used directly to achieve the same effect. This means that all annotation attributes which support placeholders already also support expressions now.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants