原因:org.springframework.expression.spel.SpelParseException:表达式[] @ 31:EL1043E:意外的令牌。应为'colon(:)',但为'rcurly(})>

问题描述 投票:2回答:1

我在发布问题之前通过了How to pass a Map<String, String> with application.properties之类的链接,但这不符合我的要求。

application.properties

soap.all.endpoints={getEmployeeRoles: ['ABC', 'EFG'], getStudentRoles: ['PQR', 'XYZ']} 

我正在使用下面的代码阅读,但给我错误。

@Value("#{${soap.all.endpoints}}")
private Map<String, List<String>> roles;

错误:

Caused by: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelParseException: Expression [{getEmployeeRoles: 'ABC', 'EFG'}] @31: EL1043E: Unexpected token. Expected 'colon(:)' but was 'rcurly(})'
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:164) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1565) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1231) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    ... 44 common frames omitted
Caused by: org.springframework.expression.spel.SpelParseException: Expression [{getEmployeeRoles: 'ABC', 'EFG'}] @31: EL1043E: Unexpected token. Expected 'colon(:)' but was 'rcurly(})'
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.internalException(InternalSpelExpressionParser.java:1041) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatToken(InternalSpelExpressionParser.java:923) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.maybeEatInlineListOrMap(InternalSpelExpressionParser.java:667) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatStartNode(InternalSpelExpressionParser.java:519) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPrimaryExpression(InternalSpelExpressionParser.java:350) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatUnaryExpression(InternalSpelExpressionParser.java:344) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatPowerIncDecExpression(InternalSpelExpressionParser.java:303) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatProductExpression(InternalSpelExpressionParser.java:281) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatSumExpression(InternalSpelExpressionParser.java:263) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatRelationalExpression(InternalSpelExpressionParser.java:218) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalAndExpression(InternalSpelExpressionParser.java:205) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatLogicalOrExpression(InternalSpelExpressionParser.java:192) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.eatExpression(InternalSpelExpressionParser.java:153) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:131) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:61) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:33) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpressions(TemplateAwareExpressionParser.java:121) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseTemplate(TemplateAwareExpressionParser.java:62) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:49) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:142) ~[spring-context-5.2.2.RELEASE.jar:5.2.2.RELEASE]
    ... 48 common frames omitted

我通过了类似的链接:如何在发布问题之前通过application.properties通过Map ,但这不能满足我的要求。 application.properties soap.all ....

spring spring-el
1个回答
1
投票

我能够使用]解决>

您可以使用类似于SPEL json的语法在属性文件中编写一个简单的映射或列表的映射。

© www.soinside.com 2019 - 2024. All rights reserved.