我正在尝试了解 Spring Boot,但在尝试将 Selenium 集成到我的 Spring Boot 应用程序中时遇到了一些问题。我正在尝试实现一个简单的网页,其中有一个输入框和按钮。输入框将包含一个 URL,然后该按钮将启动一个 selenium 浏览器,导航到输入的 URL。
我目前有一个简单的 Spring Boot 应用程序,包含以下内容:
索引.html
包含一个传递给 myController 的输入表单(用户在此处键入 URL)。
myController.java
@Controller
public class myController {
@Autowired
private WebDriver driver;
....
}
pom.xml
含有硒..
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
当我运行我的项目时,我的错误:
APPLICATION FAILED TO START
Description:
Field driver in com.project.myController required a bean of type 'org.openqa.selenium.WebDriver' that could not be found.
Action:
Consider defining a bean of type 'org.openqa.selenium.WebDriver' in your configuration.
我正在尝试创建 Selenium WebDriver 的实例,以便我可以在需要时使用它。我只在这个控制器中需要它,所以我在这里声明了它。我缺少什么?任何帮助将不胜感激。先感谢您。
您需要有一个 WebDriver 实例,例如:
@Bean
public WebDriver webDriver() {
return new FirefoxDriver();
//OR return new ChromeDriver();
}
在您的配置类之一中。那将是任何带有注释的东西@Configuration
或包含此内容的注释;在最基本的 Spring Boot 应用程序(如 Spring Boot 示例中使用的)中,这可能是这样的:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
// Your beans go here
}
because @SpringBootApplication
注释为@SpringBootConfiguration
其注释为@Configuration
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)