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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With