In spring/junit you can load application context files using @ContextConfiguration such as
@ContextConfiguration({"classpath:a.xml", "classpath:b.xml"})
I have a requirement where if I see a special annotation on a test class then add another XML context file dynamically. For example:
@ContextConfiguration({"classpath:a.xml", "classpath:b.xml"})
@MySpecialAnnotation
class MyTest{
...
}
In the above example I would look for @MySpecialAnnotation and add special-context.xml also. What is the best way to do this? I have looked at this for a while and it seems like sub-classing my own ContextLoader which is one of the parameters to @ContextConfiguration is the best approach? Is this correct? Is there a better way to do this?
It turns out the best solution is to create my own ContextLoader. I did this by extending the abstract one.