有沒有辦法改變文件的屬性?我試圖用Spring和Jetty並行運行硒測試,所以我試圖配置數據庫的url,jettyserver的端口和selenium服務器的端口。這樣我就可以初始化可運行測試的兩臺或更多臺服務器。在春天設置屬性
我server.properties文件包含此:
jdbc.url=jdbc:hsqldb:hsql://localhost/bibliothouris_scenario
jetty.port=8081
seleniumServer.port=4444
我可以提供一個PropertyPlaceholderConfigurer讀取這些屬性,我需要的數據庫URL,jettyport和seleniumserver端口要靈活。
我已經宣佈他們是這樣的:
在我的applicationContext.xml:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:server.properties</value>
</property>
</bean>
<bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
在serverContext.xml文件:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:server.properties</value>
</property>
</bean>
<bean class="com.~companyName~.bibliothouris.jetty.JettyServer" init-method="start" destroy-method="stop">
<constructor-arg value="${jetty.port}" />
<constructor-arg ref="dataSource" />
</bean>
<bean class="org.openqa.selenium.server.SeleniumServer" init-method="start" destroy-method="stop">
<constructor-arg>
<bean class="org.openqa.selenium.server.RemoteControlConfiguration">
<property name="port" value="${seleniumServer.port}" />
<property name="singleWindow" value="true" />
<property name="timeoutInSeconds" value="10" />
</bean>
</constructor-arg>
</bean>
<bean class="com.thoughtworks.selenium.DefaultSelenium" init-method="start" destroy-method="stop" lazy-init="true">
<constructor-arg>
<bean class="com.thoughtworks.selenium.HttpCommandProcessor">
<constructor-arg value="localhost" />
<constructor-arg value="${seleniumServer.port}" />
<constructor-arg value="*firefox c:/~companyname~/firefox/firefox.exe" />
<constructor-arg value="http://localhost:${jetty.port}" />
</bean>
</constructor-arg>
</bean>
當我改變服務器的數據。屬性硒測試運行在正確的服務器與正確的端口,沒有失敗。
所以現在我正在尋找一種方法來更改server.properties文件中的屬性。提前
@Walle,請提供幫助的答案,我們也在這裏聲望;) – 2011-03-30 12:06:04
我需要15個聲望來做到這一點:D – Walle 2011-03-30 13:52:23
墊是正確的,你應該訪問classpath資源通過getResourceAsStream,否則你的代碼會在不同的環境中執行時破壞 – 2011-03-31 07:26:05