只有满足特定条件时,我才能在 spring 上下文中导入东西吗?
<!-- import ONLY IF current environment is NOT testing -->
<import resource="classpath:context/caching-context.xml" />
目前我正在通过在我的测试用例中导入一个完全不同的上下文来做到这一点
@ContextConfiguration(locations = { "classpath*:ApplicationContextTesting.xml" })
但也许有一个更优雅的解决方案,可以不为生产和测试维护两个单独的应用程序上下文。
最佳答案
使用 Spring 配置文件。
<beans profile="not_test">
<import resource="classpath:context/caching-context.xml" />
</beans>
更多信息请参见 Spring documentation在 blog post 上.
关于java - 在 spring 应用程序上下文中有条件地导入资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16711760/