我正在尝试通过 SpEL 过滤 xml 配置文件中的列表集合
这是我的课
public class PCCollection implements MarketPC {
private Collection<PersonalComputer> pcCollection;
public PCCollection(Collection<PersonalComputer> pcCollection) {
this.pcCollection = pcCollection;
} ...
}
这是该类的 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类
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?
这有什么问题吗?我尝试用谷歌搜索它,但所有答案都使用注释,但在此之前我想了解如何在配置文件中工作。
最佳答案
maybe not public or not valid?
您应该为 pcCollection
创建一个名为 getPcCollection
关于java - org.springframework.expression.spel.SpelEvaluationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51686944/