I am studying Spring and trying to create a bean and pass a parameter to it. My bean in the Spring configuration file looks like this:
@Bean
@Scope("prototype")
public InputFile inputFile (String path)
{
InputFile inputFile = new InputFile();
inputFile.setPath(path);
return inputFile;
}
Class InputFile:
public class InputFile {
String path = null;
public InputFile(String path) {
this.path = path;
}
public InputFile() {
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
and in the main method I have:
InputFile inputFile = (InputFile) ctx.getBean("inputFile", "C:\\");
C:\\ is the parameter I'm trying to pass.
I run the application and get a root exception:
Called: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualification bean of type [java.lang.String] found for dependency: expected at least 1 bean that qualifies as an outsourcing candidate for this dependency. Dependency Annotations: {}
What have I done wrong and how to fix it?
source
share