org.springframework.expression.spel.SpelEvaluationException

时间:2018-08-04 15:15:16

标签: java spring dependency-injection inversion-of-control

我正在尝试通过SpEL过滤xml配置文件中的列表集合

这是我的课程

public class PCCollection implements MarketPC {

private Collection<PersonalComputer> pcCollection;

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

这是此类和填充集合的

 <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>

和customPC类

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搜索它,但是所有答案都使用了注释,但是在此之前,我想了解如何在配置文件中工作。

1 个答案:

答案 0 :(得分:0)

  

可能不公开或无效?

您应该为pcCollection创建名为getPcCollection的get方法