How to collect and inject all beans of a given type in Spring XML configuration

前端 未结 3 1242
时光说笑
时光说笑 2020-12-01 08:17

One of the strongest accents of the Spring framework is the Dependency Injection concept. I understand one of the advices behind that is to separate general high-level mecha

3条回答
  •  不思量自难忘°
    2020-12-01 08:23

    Old question and in Spring 3.1 it is possible:

    public class PluginPrototypeTest extends ASpringWebTest {
      @Autowired
      Collection repos;
    
      @Test
      public void cacheTest() {
        assertNotNull(repos);
        assertEquals(2, repos.size());
        for(IDummyRepo r: repos){
          System.out.println(r.getName());
        }
      }
    }
    
    @Repository
    public class DummyRepo implements IDummyRepo {
      @Override
      public String getName(){
        return "DummyRepo";
      }
    }
    @Repository
    public class DummyRepo2 implements IDummyRepo {
      @Override
      public String getName(){
        return "DummyRepo2";
      }
    }
    

提交回复
热议问题