0
我從我的testConfig.xml中自動添加了一些bean,並且它工作正常,但是當我想自動裝載一個屬性文件時它會給出null,那麼屬性文件就在我的xml文件夾中。我testConfig.xml看起來是這樣的:爲什麼autowired屬性文件爲空?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd" >
<bean id="base" class="java.net.URI">
<constructor-arg value="http://localhost:8080/MySite" />
</bean>
<bean id="siteBase" class="java.net.URI">
<constructor-arg value="http://localhost:8080/MySite/site" />
</bean>
<bean id="adminBase" class="java.net.URI">
<constructor-arg value="http://localhost:8080/MySite/admin" />
</bean>
<bean id="firefoxDriver" class="org.openqa.selenium.firefox.FirefoxDriver" destroy-method="quit"/>
<context:annotation-config/>
<util:properties id="seleniumSelectors" location="classpath:selenium/selenium-selectors.properties"/>
</beans>
,在這裏我想自動裝配它:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/testConfig.xml" })
public abstract class AbstractUITest extends TestCase{
@Autowired
protected URI base;
@Autowired
protected URI siteBase;
@Autowired
protected URI adminBase;
@Autowired
protected WebDriver firefoxDriver;
@Autowired
@Qualifier("seleniumSelectors")
protected Properties selectors;
protected By getBySelectorKey(String key){
if(key.endsWith(".xpath")){
return By.xpath(selenium.getProperty(key));
}
}
就在選擇對象爲空,我不`噸知道爲什麼,任何建議?
更新2:
我犯了一個錯誤everithing爲空時,選擇是null.I在我的測試cheked初始化運行之前自動裝配,在某種程度上這
public class AdminCandidatesPageUITest extends AbstractAdminUITest {
private By COMPONENT_QUERY_TEXTBOX_EMAIL = getBySelectorKey("admin.candidates.edit.textbox.email.xpath");
private By COMPONENT_QUERY_TEXTBOX_EMAIL_ERROR = getBySelectorKey("admin.candidates.edit.textbox.email.errors.xpath");
應該運行seleniumSelector被自動裝配後。任何建議?
我試着移動 下的 ,但仍然給出null –
FAndrew
嘗試臨時替換'
AlexR
你能寫一個例子嗎?我不知道我是否正確寫入。我做這樣的事情並沒有工作: 的 \t \t \t <屬性名= 「基名」 價值=「類路徑:硒/硒的選擇.properties「/> \t \t and in class \t @Autowired 受保護的屬性seleniumSelectors; –
FAndrew