【发布时间】:2020-04-20 10:42:53
【问题描述】:
使用Spring框架,我想创建一个Person类型的bean对象,而这个bean对象有一个queue类型的Queue<Integer>属性,如何通过XML给属性注入值?
春季版是4.3
但我找不到队列。
我尝试使用<bean>元素,但是bean的queue属性为空。
对象如下
public class People {
private int id;
private Queue<Integer> queue;
// add constructor
// add get and set
}
applicationContext.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="..." class="...">
<property name="queue">
<bean class="java.util.ArrayDeque">
//How should I add values to the queue object
</bean>
</property>
</bean>
</beans>
【问题讨论】:
-
“属性无法填写”是什么意思,有没有报错信息?
-
@samabcde 我找不到如何配置队列。我应该如何向队列对象添加值
标签: java spring dependency-injection