Skip to content

Document supported characters for identifiers in SpEL expressions #24359

@holicc

Description

@holicc

Original title: Does SpEL support Chinese variables?

I try to use SpEL to execute some code which includes some Chinese variables.

void test() {
        SimpleEvaluationContext evaluationContext = SimpleEvaluationContext
                .forReadWriteDataBinding()
                .withMethodResolvers(DataBindingMethodResolver.forInstanceMethodInvocation())
                .build();

        evaluationContext.setVariable("中文", 1);

        ExpressionParser parser = new SpelExpressionParser();
        Expression expression = parser.parseExpression("#中文 == 1");

        Boolean value = expression.getValue(evaluationContext, Boolean.class);

        System.out.println(value);
 }

Exception stack trace:

java.lang.IllegalStateException: Cannot handle (20013) '中'
	at org.springframework.expression.spel.standard.Tokenizer.process(Tokenizer.java:268)
	at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:127)
	at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:61)
	at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:33)
	at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:52)
	at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:43)

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions