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

Pass evaluationContext when parsing expressions for CircuitBreaker properties #293

Closed
garyrussell opened this issue Apr 20, 2022 Discussed in #291 · 1 comment · Fixed by #295
Closed

Pass evaluationContext when parsing expressions for CircuitBreaker properties #293

garyrussell opened this issue Apr 20, 2022 Discussed in #291 · 1 comment · Fixed by #295

Comments

@garyrussell
Copy link
Contributor

Discussed in #291

Originally posted by evgenvi April 20, 2022
The evaluationContext is passed when parsing all the expression parameters of Retryable and Backoff annotations except for CircuitBreaker annotation in AnnotationAwareRetryOperationsInterceptor.

For example, it's passed when parsing delayExpression parameter:
PARSER.parseExpression(resolve(delayExpression),PARSER_CONTEXT) .getValue(this.evaluationContext, Long.class);

For example, it isn't passed when parsing openTimeoutExpression parameter:
PARSER.parseExpression(resolve(circuit.openTimeoutExpression()), PARSER_CONTEXT) .getValue(Long.class);

if we try to resolve this snippet of code:

public static class Configs {
public int maxAttempts = 10;
public long openTimeout = 10000;
public long resetTimeout = 10000;
}

@Bean
public Configs configs() {
    return new Configs();
}

@Component
public static class Service {
    @CircuitBreaker(
            maxAttemptsExpression = "#{@configs.maxAttempts}",
            openTimeoutExpression = "#{@configs.openTimeout}",
            resetTimeoutExpression = "#{@configs.resetTimeout}"
    )
    public String method() {
        return "value";
    }
}

The only maxAttempts parameter will be resolved correctly and we will get an exception for the other two parameters
org.springframework.expression.spel.SpelEvaluationException: EL1057E: No bean resolver registered in the context to resolve access to bean 'configs'

@garyrussell could you tell me if there is any reason why the evaluation context isn't passed when parsing expressions for CircuitBreaker properties?

@garyrussell garyrussell added this to the 1.3.4 milestone Apr 20, 2022
@garyrussell garyrussell modified the milestones: 1.3.4, 2.0.0-M1 Apr 20, 2022
@artembilan
Copy link
Member

I guess they have to be simplified: maxAttemptsExpression = "configs.maxAttempts" since we really talk about expressions and their ability to be resolved against beans.

garyrussell added a commit to garyrussell/spring-retry that referenced this issue Apr 20, 2022
artembilan pushed a commit that referenced this issue Apr 20, 2022
artembilan pushed a commit that referenced this issue Apr 20, 2022
Resolves #293

**cherry-pick to 1.3.x**

# Conflicts:
#	src/test/java/org/springframework/retry/annotation/CircuitBreakerTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants