-->

spring @Cacheable with Ehcache, spel find null for

2019-01-15 22:10发布

问题:

I have a similar problem which but sometimes it works. The error described only happens once in a while.

I am using spring 3.2.5 and ehcache 2.6.5.

Exception trace:

org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'applicationID' cannot be found on null
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:213)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43)
        at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:82)
        at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
        at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:89)
        at org.springframework.cache.interceptor.ExpressionEvaluator.key(ExpressionEvaluator.java:95)
        at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.generateKey(CacheAspectSupport.java:452)
        at org.springframework.cache.interceptor.CacheAspectSupport.inspectCacheables(CacheAspectSupport.java:281)
        at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:199)
        at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at com.sun.proxy.$Proxy85.getMailOrigin(Unknown Source)
        at com.myApplication.MailFilterServiceImpl.isValid(ApplicationServiceImpl.java:134)

My caching code is a follows:

MailFilterServiceImpl
    @Cacheable(value="mailClientsCache", key="#mb.applicationID")
        public MailClientBean getMailOrigin(MailBean mb){}

When this happens: When I have a jenkins configured to build and autodeploy to tomcat7 / when I use maven to build in the eclipse WS and deploy to tomcat7.

When this works perfectly: After it has failed once, if I edit the MailFilterServiceImpl.java simply with some spaces to make it recompile in eclipse and restart the tomcat7 server.

I need to make it work in a CI scenario.

[Update] Setting compiler option debug:true works around this problem. The optimized doesnt seem to have any say.

<debug>true</debug>
<optimize>true</optimize>

回答1:

Your description makes one thing clear: It does not work when you compile with javac, but it does work with the Eclipse compiler ecj. You might be compiling without debugging information.