@Resource 註解的一個用法

 

 @Bean("readDataSources")
    public List<DataSource> readDataSources(){
        List<DataSource> dataSources=new ArrayList<DataSource>();
        dataSources.add(readDataSourceOne());
        dataSources.add(readDataSourceTwo());
        return dataSources;
    }

  有個類裏有個bean,(bean在ioc容器是單例)另一個類裏需要用到這個bean,怎麼注入這個bean呢,

如下,觀察發現注入的是這個方法的返回參數

    @Resource(name = "readDataSources")
    private List<DataSource> readDataSources;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章