Can I import things in a spring context only if a certain condition is met?
<!-- import ONLY IF current environment is NOT testing -->
<import resource="classpath:context/caching-context.xml" />
currently I am doing that by importing a totally different context in my testcases
@ContextConfiguration(locations = { "classpath*:ApplicationContextTesting.xml" })
but maybe there is a more elegant solution to not maintain two separate application contexts for production and testing.
Use Spring profiles.
<beans profile="not_test">
<import resource="classpath:context/caching-context.xml" />
</beans>
More information in Spring documentation and on the blog post.
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