Java SpEL 解析有效表达式,表达式中还有更多数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29534883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 08:10:36  来源:igfitidea点击:

SpEL parsing a valid expression, there is still more data in expression

javaspringspring-el

提问by Udhay

I am using Spring Expression Language (SpEL) and created a sample program. The code snippet is

我正在使用 Spring 表达式语言 (SpEL) 并创建了一个示例程序。代码片段是

ExpressionParser parser=new SpelExpressionParser();
Expression expression=parser.parseExpression("Hello SPEL");

But got below error.

但得到以下错误。

Exception in thread "main" org.springframework.expression.spel.SpelParseException: EL1041E:(pos 6): After parsing a valid expression, there is still more data in the expression: 'SPEL'
    at org.springframework.expression.spel.standard.InternalSpelExpressionParser.doParseExpression(InternalSpelExpressionParser.java:116)
    at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:56)
    at org.springframework.expression.spel.standard.SpelExpressionParser.doParseExpression(SpelExpressionParser.java:1)
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:66)
    at org.springframework.expression.common.TemplateAwareExpressionParser.parseExpression(TemplateAwareExpressionParser.java:56)

回答by Zaheylu

Try

尝试

Expression expression=parser.parseExpression("'Hello SPEL'");

instead.

反而。

The parameter is a String, but the parser needs to know that this is a string, because you can parse other things as well.

参数是一个字符串,但解析器需要知道这是一个字符串,因为你也可以解析其他东西。

For more information, have a look here.

有关更多信息,请查看此处

回答by MAnoj Sarnaik

Try this

尝试这个

Expression expression=parser.parseExpression("'Hello SPRING'");

回答by Abdessattar NOISSI

I m facing the same exception when injecting a bean with xml file :

使用 xml 文件注入 bean 时,我面临同样的异常:

 <bean id="myBean"
          class="mypackage.mybean"
          destroy-method="destroy"
          p:filePath=
                  "#{systemProperties'java.io.tmpdir'}#{systemProperties'file.separator'}somefile.txt"/>

the problem disappear when using: []:

使用时问题消失:[]

<bean id="myBean"
          class="mypackage.mybean"
          destroy-method="destroy"
          p:filePath=
                  "#{systemProperties['java.io.tmpdir']}#{systemProperties['file.separator']}somefile.txt"/>

My this help you to solve your problem ,

我的这可以帮助您解决您的问题,

for more information about this problem please referto this issue :

有关此问题的更多信息,请参阅此问题:

回答by Shubh

If you are putting that in your spring beans xml file try putting it like this

如果你把它放在你的 spring beans xml 文件中,试着把它像这样

#{'Hello Spel'}.

回答by Smart Coder

I am using Spring web flow and moved from ognl to Spring 5 WebFlowSpringELExpressionParser and replaced the @package.class.method() with bean.method() and bean was declared in servlet.xml.

我正在使用 Spring web flow 并从 ognl 移动到 Spring 5 WebFlowSpringELExpressionParser 并用 bean.method() 替换 @package.class.method() 并且 bean 在 servlet.xml 中声明。