如何连接Spring bean的引用对象

时间:2014-05-15 08:47:13

标签: java spring

这是我的示例bean:

@Component
public class FirstBean {
    private List<String> foo;

    // Getters and Setters
}

现在我想将foo列表从FirstBean连接到SecondBean bean。像这样或者可能在XML配置文件中:

@Component
public class SecondBean {
    @Autowired
    private List<String> foo
}

如何连接bean的引用对象而不是bean本身?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以按照以下步骤操作:

@Component
public class TheList {

    private List<String> theList;

}

@Component
public class FirstBean {

    @Autowired
    private TheList foo;

}

@Component
public class SecondBean {

    @Autowired
    private TheList foo;

}