I'm writing integration tests with SpringJUnit4. I got question. How in @ContextConfiguration I can use XML based config and Java-based at same time. As I know I couldn't do it, but maybe there exist backdoor? Thanks in advance!
2 Answers
You could create static inner @Configuration class in your test class and use @ContextConfiguration annotation on your class without any parameters. As stated in the article below, Spring will automatically look for static inner @Configuration class if no XML locations or config classes are passed to the annotation.
You can then import your XML config and Java config classes using @Import and @ImportResource annotations. So your base class for your Spring tests could look something like this:
@ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) public class BaseSpringTest { @Configuration @Import(BaseConfig.class) @ImportResource({ "classpath:applicationContext-hibernate.xml" }) public static class ContextConfig {} } Sources