I have an application that is working with Spring Boot 3.4.0, but with 3.4.1, I get an unexpected exception:

org.springframework.expression.EvaluationException: Calling method 'containsBean' is forbidden for type 'class org.springframework.web.context.support.GenericWebApplicationContext' in this expression context.

The Thymeleaf excerpt is:

  <head th:with="elasticApmConfiguration=${T(org.thymeleaf.spring6.context.SpringContextUtils).getApplicationContext(#ctx).containsBean('someBean')?T(org.thymeleaf.spring6.context.SpringContextUtils).getApplicationContext(#ctx).getBean('someBean'):null}"

I don't see why calling the containsBean method invocation should be forbidden in this context.

Here's the full exception stack trace:

Caused by: org.springframework.expression.EvaluationException: Calling method 'containsBean' is forbidden for type 'class org.springframework.web.context.support.GenericWebApplicationContext' in this expression context.
    at app//org.thymeleaf.spring6.expression.ThymeleafEvaluationContext$ThymeleafEvaluationContextACLMethodResolver.resolve(ThymeleafEvaluationContext.java:276)
    at app//org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:218)
    at app//org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:148)
    at app//org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:398)
    at app//org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:97)
    at app//org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:203)
    at app//org.springframework.expression.spel.ast.Ternary.getValueInternal(Ternary.java:54)
    at app//org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:116)
    at app//org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:338)
    at app//org.thymeleaf.spring6.expression.SPELVariableExpressionEvaluator.evaluate(SPELVariableExpressionEvaluator.java:265)
    ... 254 more

Comment From: candrews

Here's the source in Thymeleaf from which the exception originates: https://github.com/thymeleaf/thymeleaf/blob/thymeleaf-3.1.2.RELEASE/lib/thymeleaf-spring6/src/main/java/org/thymeleaf/spring6/expression/ThymeleafEvaluationContext.java#L277

Comment From: candrews

This appears to be an issue with Thymeleaf: https://github.com/thymeleaf/thymeleaf/issues/1025