get all Beans of type in SpringJUnit4ClassRunner

584 Views Asked by At

I have problems to find a suitable answer for my following test class:

@ContextConfiguration("classpath:services.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class RunnableServiceTest {

   @Test
   public void testConfiguration(){
       Collection<Service> lAllService = >>getBeansOfType(Service.class)<<;
       assertFalse(lAllService.isEmpty());
   }
}

I want to collect all Spring managed beans from the bounded context services.xml that are type of Service.

I am pretty sure there must be something like this but I dont know what I have to search for.

Thx a lot for your help.

Stefan

1

There are 1 best solutions below

0
schrieveslaach On BEST ANSWER

You can use an autowired List

@ContextConfiguration("classpath:services.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class RunnableServiceTest {

   @Autowired
   private List<Service> lAllService;

   @Test
   public void testConfiguration(){
       assertFalse(lAllService.isEmpty());
   }
}