org.springframework.expression.spel.SpelEvaluationException: EL1030E


問題與分析

在本地開發項目時發現報錯如下:

org.springframework.expression.spel.SpelEvaluationException: EL1030E: The operator 'ADD' is not supported between objects of type 'java.lang.String' and 'null'
	at org.springframework.expression.spel.ExpressionState.operate(ExpressionState.java:240)
	at org.springframework.expression.spel.ast.OpPlus.getValueInternal(OpPlus.java:80)
	at org.springframework.expression.spel.ast.OpPlus.getValueInternal(OpPlus.java:85)
	at org.springframework.expression.spel.ast.OpPlus.getValueInternal(OpPlus.java:83)
	at org.springframework.expression.spel.ast.OpPlus.getValueInternal(OpPlus.java:83)
	at org.springframework.expression.spel.ast.OpPlus.getValueInternal(OpPlus.java:83)
	at org.springframework.expression.spel.ast.OpPlus.getValueInternal(OpPlus.java:83)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:109)
	at org.springframework.expression.spel.standard.SpelExpression.getValue
....
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

從堆棧信息可以看出,該異常與spel有關。spel指的是Spring Expression Language,結合問題代碼進行分析,可以認為該異常與spring表達式有關。而在我的代碼里,只有@Cacheable注解里使用到了spel,如下:

    @Cacheable(key = "#root.target.getCacheKeyPrefix() + '::' + + #root.target.getRootDomain() + '-' + #root.target.getLocale() + '-' + #searchLabelKey")
    public String getFromRootDomain(final String labelId, final String locale, final String searchLabelKey) {
        
		// TODO
        return null;
    }

很顯然,在使用到該注解時,由於這里的spring表達式有問題,最終在解析時拋出了異常。經過檢查發現,這里犯了個很逗的錯誤,就是連續使用了兩個+,導致解析無法通過,改正后如下:

@Cacheable(key = "#root.target.getCacheKeyPrefix() + '::' + #root.target.getRootDomain() + '-' + #root.target.getLocale() + '-' + #searchLabelKey")

而之所以之前沒能發現這個問題,是因為沒有啟用redis cache,導致避開了這個問題。目前剛開始了解spel這門表達式語言,在此記錄下這個問題,方便日后回顧分析,下面順便貼上官方的一篇中譯文檔。

參考鏈接


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM