Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将bean配置为';可选';在spring applicationcontext.xml中_Spring_Selenium_Applicationcontext_Optional - Fatal编程技术网

将bean配置为';可选';在spring applicationcontext.xml中

将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

我在spring
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.`