1

I have a junit test class with following annotations :

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:custom-context.xml")

There exists a class in another context that is required in my test that is autowired so I require this context to be loaded. How can this be implemented ?

I've tried :

@ContextConfiguration("classpath:custom-context.xml , classpath:custom-context2.xml")

But this does now work as it does not seem to load multiple contexts using the , delimiter.

blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • Take a look at http://stackoverflow.com/questions/14946298/spring-junit-load-application-context-for-tests. If you have some similar naming pattern you can use pattern paths too. – Shailendra Nov 18 '13 at 16:56

2 Answers2

3

Also can use widcard like this:

@ContextConfiguration({"classpath:custom-*.xml" })
Baron.Zhao
  • 31
  • 1
2

Use an array of strings, like :

@ContextConfiguration(locations={ "classpath:custom-context.xml" , "classpath:custom-context2.xml" })

from spring api doc

Pyranja
  • 3,529
  • 22
  • 24