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
SpEL parsing a valid expression, there is still more data in expression
提问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
回答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 中声明。