I have a parameterized constructor. How can I make use of @Autowired
annotation within it?
Below is a sample snippet:
@Autowired
private MyImplClass myImplClass;
I have a parameterised constructor in MyImplClass
like below:
public class MyImplClass{
WebDriver driver = new FireFoxDriver();
public MyImplClass(WebDriver driver){
this.driver = driver;
}
}
I need to pass driver to MyImplClass
. How this can be achieved using @Autowired
?
One approach is to create the WebDriver on your spring context:
<bean class="org.openqa.selenium.firefox.FirefoxDriver"/>
And inject it to MyImplClass using constructor autowiring
@Component
public class MyImplClass{
private WebDriver driver;
@Autowire
public MyImplClass(WebDriver driver){
this.driver = driver;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With