简体   繁体   中英

get all Beans of type in SpringJUnit4ClassRunner

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

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());
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM