将bean配置为';可选';在spring applicationcontext.xml中
我在spring将bean配置为';可选';在spring applicationcontext.xml中,spring,selenium,applicationcontext,optional,Spring,Selenium,Applicationcontext,Optional,我在springappingcontext.xml中定义了以下bean <bean id ="seleniumDriver" class="org.openqa.selenium.firefox.FirefoxDriver"> <constructor-arg><ref bean="capabilities"/></constructor-arg> </bean> 我有一个不想加载那个bean的需求,所以我运行我的项目时匹配w
appingcontext.xml中定义了以下bean
<bean id ="seleniumDriver" class="org.openqa.selenium.firefox.FirefoxDriver">
<constructor-arg><ref bean="capabilities"/></constructor-arg>
</bean>
我有一个不想加载那个bean的需求,所以我运行我的项目时匹配webdriver参数,即“mvn clean test”,但是我得到了下面的异常
原因:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'seleniumDriver' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.openqa.selenium.firefox.FirefoxDriver]: Constructor threw exception; nested exception is org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed.`
我在这里读了一些帖子,了解到我们可以在java类中使用@Autowired(required=false)
或重写applicationcontext
,但我不想接触java代码,而是想通过XML配置来实现,有什么办法吗?使用bean配置文件,并在需要时激活该配置文件中的bean。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'seleniumDriver' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.openqa.selenium.firefox.FirefoxDriver]: Constructor threw exception; nested exception is org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed.`