弹簧性能替代测试和生产 [英] spring property substitution for test and production

查看:95
本文介绍了弹簧性能替代测试和生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在春季遇到了此问题以进行财产替代

I ran into this for property substitution in spring

<context:property-placeholder location="esb-project-config.properties"/>

但是不幸的是,我们不希望在xml文件中使用它,因为我们想在测试中重新使用该文件,但要交换test.properties文件进行测试. IE.我们要测试所有生产绑定,但是要使用适合于测试的属性,例如localhost.如何加载具有不同属性文件的ApplicationContext?

but unfortunately, we don't want this in the xml file as we want to re-use the file in our tests but swap in the test.properties file for test. ie. we want to test all the production bindings but with properties that are suitable for test like localhost for instance. How can we load the ApplicationContext but with different properties files?

谢谢, 院长

推荐答案

将属性占位符配置放入额外的spring xml配置文件中.

Put the property-placeholder configuration in an extra spring xml configuration file.

例如:

  • applicationContext.xml-用于没有任何属性占位符配置的常规配置
  • applicationContext-config.xml-仅包含一个用于加载生产配置文件的属性占位符.
  • testApplicationContext.xml.该文件includeapplicationContext.xml,并与其他属性文件一起使用属性占位符.
  • applicationContext.xml -- for the normal configration without any property-placeholder configuration
  • applicationContext-config.xml -- contains only a property-placeholder that load the production config file.
  • testApplicationContext.xml. This file includes the applicationContext.xml and uses a property-placeholder with an other properties file.

在Web应用程序中,您可以使用applicationContext*.xml模式加载所有生产spring上下文文件.

In a Web App you could load all production spring context files with this pattern applicationContext*.xml.

对于测试,您只需要加载testApplicationContext.xml,它将包括常规配置,但具有其他属性.

For the tests you need only to load testApplicationContext.xml this will include the normal config, but with other properties.

这篇关于弹簧性能替代测试和生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆