java Spring 应用程序错误:EL1008E

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35892856/
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-11-03 00:43:24  来源:igfitidea点击:

Spring App Error: EL1008E

javaspringspring-integrationspring-elspring-dsl

提问by DaniloV

I have been working on a Spring Integration project using Enterprise Integration Patterns to consume MQ messages, do some processing, then write them to another queue.

我一直在研究 Spring Integration 项目,使用企业集成模式来使用 MQ 消息,进行一些处理,然后将它们写入另一个队列。

My problem appears very similar to this onehowever the accepted answer hasn't fixed it for me.

我的问题看起来与这个问题非常相似,但是接受的答案并没有为我解决。

After receiving a response from an external web service, my @Cacheable@Componentclass returns the body as an ArrayList. I am getting the following error:

收到来自外部 Web 服务的响应后,我的@Cacheable@Component类将正文作为ArrayList. 我收到以下错误:

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 1): Property or field 'valid' cannot be found on object of type 'java.util.ArrayList' - maybe not public?

Here is, what I believe to be, the offending class:

这是,我认为是,有问题的班级:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.curator.x.discovery.ServiceCache;
import org.apache.curator.x.discovery.ServiceInstance;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

@Component
public class DirectoryRepo {

    @Autowired
    private CacheManager cacheManager;

    @Autowired
    private ServiceCache<ServiceDetail> directoryServiceCache;

    @Autowired
    private RestTemplate restTemplate;

    private ArrayList<X> response;

    private static final Logger logger = LogManager.getLogger();

    @Cacheable(value = "X", unless = "!#result.valid")
    public ArrayList<X> checkForX(String a,
            String b, String c, String d) {

            try {

                //code omitted

                HttpHeaders headers = new HttpHeaders();
                headers.add("token", service.getPayload().getToken());

                ResponseEntity<X[]> responseEntity = restTemplate
                        .exchange(request, HttpMethod.GET, new HttpEntity<>(
                                headers), X[].class);


                if (responseEntity != null && responseEntity.hasBody()) {

                    response = new ArrayList<X>(Arrays.asList(responseEntity.getBody()));
                    return response;
                } else {
                    logger.debug("received unexpected responseEntity: {}",
                            responseEntity);
                }
            } catch (RestClientException e) {
                logger.error("failed to get X - {}",
                        e.getMessage(), e);
            }

        throw new ServiceException(
                "failed to get X - Directory service unavailable");
    }

    public ArrayList<X> getResponse() {
        return this.response;
    }

    /**
     * Clears out all entries from the X cache.
     */
    @CacheEvict(value = "X", allEntries = true)
    public void clearXCache() {
        logger.trace("cacheManager:{}", cacheManager);
    }

}

As you can see I have tried setting a public getter method, but the exception still occurs:

如您所见,我已尝试设置公共 getter 方法,但仍然出现异常:

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 1): Property or field 'valid' cannot be found on object of type 'java.util.ArrayList' - maybe not public
?
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE]
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE
]
        at org.springframework.expression.spel.ast.PropertyOrFieldReference.access
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="appName" path="/appName" copyXML="true">

</Context>
0(PropertyOrFieldReference.java:46) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:374) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4 .RELEASE] at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:170) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.expression.spel.ast.OperatorNot.getValueInternal(OperatorNot.java:47) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.expression.spel.ast.OperatorNot.getValueInternal(OperatorNot.java:36) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299) ~[spring-expression-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.cache.interceptor.ExpressionEvaluator.unless(ExpressionEvaluator.java:123) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.canPutToCache(CacheAspectSupport.java:623) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELE ASE] at org.springframework.cache.interceptor.CacheAspectSupport$CachePutRequest.apply(CacheAspectSupport.java:675) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:361) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:302) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE] at somepackage.DirectoryRepo$$EnhancerBySpringCGLIB$$f7709589.checkForX(<generated>) ~[DirectoryRepo.class:?] at somepackage.DirectoryService.getX(DirectoryService.java:66) ~[DirectoryService.class:?]

context.xml:

上下文.xml:

##代码##

采纳答案by Gary Russell

The error seems pretty clear to me.

这个错误对我来说似乎很清楚。

It's not clear what you are trying to do. The #resultvariable is a reference to the ...er... result of calling the method- i.e. the ArrayList.

目前尚不清楚您要做什么。该#result变量是对 ...er... 的引用result of calling the method- 即ArrayList.

ArrayListdoes not have a isValid()or getValid()method.

ArrayList没有isValid()orgetValid()方法。

The documentation about Conditional Cachingdescribes what variables are available to you.

关于条件缓存的文档描述了哪些变量可供您使用。

As you can see I have tried setting a public getter method

如您所见,我尝试设置公共 getter 方法

I don't see any such thing.

我没有看到任何这样的事情。

You can do things like result.size() > 0, a != 'foo'.

您可以执行诸如result.size() > 0, 之类的操作a != 'foo'