org.springframework.expression.spel.SpelEvaluationException

org.springframework.expression.spel.SpelEvaluationException

我正在尝试通过 SpEL

在 xml 配置文件中过滤列表集合

这是我的class

public class PCCollection implements MarketPC {

private Collection<PersonalComputer> pcCollection;

public PCCollection(Collection<PersonalComputer> pcCollection) {
    this.pcCollection = pcCollection;
}   ...
}

这是用于此 class 和填充集合

的 bean
 <bean id="marketPC" class="PCCollection">
    <constructor-arg name="pcCollection">
        <list>
            <ref bean="customPC"/>
            <bean class="MyCustomPC" scope="prototype">
            <constructor-arg name="mother" ref="msiMother"/>
            <constructor-arg name="processor" ref="asusProcessor"/>
            <constructor-arg name="storage" ref="gigabyteStorage"/>
            <constructor-arg name="ram" ref="gigabyteRam"/>
            <constructor-arg name="video" ref="asusVideo"/>
            </bean>
      </list>
    </constructor-arg>
</bean>

和自定义PC class

public class MyCustomPC implements PersonalComputer {

private MotherBoard mother;
private Processor processor;
private Ram ram;
private StorageDevice storage;
private VideoCard video;
....}

当我尝试创建带有用于过滤我的第一个 bean 的表达式的 bean 时

 <bean id="marketPCASUS" class="PCCollection">
    <constructor-arg name="pcCollection"
    value = "#{marketPC.pcCollection.?[video eq 'asusVideo']}">
    </constructor-arg>
</bean>

我收到异常

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'pcCollection' cannot be found on object of type 'PCCollection' - maybe not public or not valid?

这有什么问题?我尝试 google 它,但所有答案都使用注释,但在此之前我想了解如何在配置文件中工作。

maybe not public or not valid?

您应该为 pcCollection 创建一个名为 getPcCollection

的 get 方法