Search code examples
javaspringdependency-injectioninversion-of-control

org.springframework.expression.spel.SpelEvaluationException


Im trying to filter list collection in xml configuration file by SpEL

this is my class

public class PCCollection implements MarketPC {

private Collection<PersonalComputer> pcCollection;

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

this is bean for this class and fill collection

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

and customPC class

public class MyCustomPC implements PersonalComputer {

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

when i trying to create bean with expression for filtering my 1st bean

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

i'm receiving exception

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?

what is wrong with that? i tried to google it, but all answers with using annotations, but before it i want to understand how to work in configuration files.


Solution

  • maybe not public or not valid?

    you should create a get method for pcCollection named getPcCollection