我是Java spring framwork的新手。我正在使用spring框架做功能测试。作为测试的一部分,我有文件需要传递给API并从DB验证,文件数据进入DB。我使用spring来存储带有相关数据数据的测试文件。 。我的测试必须用多个文件调用API。如何从spring文件属性
DifferentValuesInBeanForFile1(请参阅spring文件)=某些具有与文件1关联的数据的bean。 DifferentValuesInBeanForFile2 =某些具有与文件2关联的数据的bean。
因此,测试可以通过validatitng数据验证API正确处理的输入文件1
<bean id="TestHappyPathPostDeal1Hotel1Deal" class="com.abc.FunctionalTests">
<property name="InDate" value="12/20/2014 00:00:00" />
<property name="OutDate" value="12/24/2014 00:00:00" />
<property name="HotelDeals">
<util:map>
<entry InputFile="fileWithDeal123.avro" value="DifferentValuesInBeanForFile1" />
<entry InputFile="fileWithDeal999.avro" value="DifferentValuesInBeanForFile1" />
</util:map>
</property>
</bean>
答案 0 :(得分:0)
我不确定我是否理解你的问题。但是,如果我这样做,那么您需要查看使用属性。您可以在spring文件的顶部添加:
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:///opt/somelocation/general.properties</value>
</list>
</property>
</bean>
然后你可以在弹簧文件中引用内容:
<bean id="config" class="com.something.SomeClassConfiguration">
<property name="hosts" value="${main.hosts}" />
<property name="clusterName" value="${main.clusterName}" />
</bean>
general.properties文件包含以下内容:
main.hosts=127.0.0.1:9160
main.clusterName=test
如果你根据编译改变了什么,你需要查看你的构建系统。我使用maven,并设置配置文件。根据我正在做的事情,我得到maven用我正在构建的系统的正确文件替换general.properties文件。
希望有所帮助。