将bean作为子类中的构造函数参数注入

时间:2013-09-11 15:37:02

标签: java spring

当父类构造函数获取该类型的列表时,如何在子类中将bean作为构造函数参数注入。

@Service
public class Parent{
    private List<MyObject> myObjectList;
    public Parent(List<MyObject> myObjectList){
        this.myObjectList = myObjectList;
    }
}

@Service
public class Child extends Parent {
    @Autowired
    public Child(MyObject myObject){
        super( ???? );
    }
}

1 个答案:

答案 0 :(得分:4)

这个怎么样?

super(Arrays.asList(new MyObject[] {myObject}));