18

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

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)

6 Answers 6

21

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.

2

Try this

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

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

 <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 refer to this issue :

4
  • Since you are not sure if this helps OP this isnt meant to be an answer. The only purpose of an answer is to solve this explicit issue of OP. And there is already an upvoted answer. Commented Dec 19, 2017 at 9:47
  • My problem is very similar to its, upvoted answer means a correct answer ? Commented Dec 19, 2017 at 16:32
  • First of all if your problem is just similar then this answer is not in the right place. An answer shell only answer explicit only this one issue OP has mentioned. An upvoted answer is not absolutely the correct answer, but since there are no comments or what so ever on the answer this implies that OP is not actice on his question and thats why there is no accepted answer sign (its just a guess though). But you can trust ,especially because this is the only answer with upvotes, that this one has high quality and solves OP's issue. Commented Dec 19, 2017 at 22:09
  • @L.Guthardt you funny kid :) Commented Jan 31 at 5:27
0

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

#{'Hello Spel'}.
0

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.

0

I was getting this:

EL1041E: After parsing a valid expression, there is still more data in the expression: 'colon(:)'

and I tried finding something in the answers above. Finally I found that in the latest version of a SpringBoot config file, the value, had been converted to a map and so the URL which was the value of the old version was now a name/value pair separated by the colon in http://....

Old value in application.yml

my:
    connection:
        url:http://www.example.com

New value

my:
    connection:
        url: "{
            url1: 'http://www.example.com',
            url1: 'http://www.example.com',
            url1: 'http://www.example.com'
        }"

The solution to the error message was to update to the config file with the map. This gave the code what it wanted.

Not the answer you're looking for? Browse other questions tagged or ask your own question.