We Are Going To Discuss About Parameter 0 of constructor in required a bean of type ‘java.lang.String’ that could not be found. So lets Start this Java Article.
Parameter 0 of constructor in required a bean of type ‘java.lang.String’ that could not be found
- Parameter 0 of constructor in required a bean of type 'java.lang.String' that could not be found
Since you do not provide the public default constructor and you added your own non-default constructor the instantiation will fail. I would suggest you to define the input file path as property like
@Value("${inputFilePath}")
. - Parameter 0 of constructor in required a bean of type 'java.lang.String' that could not be found
Since you do not provide the public default constructor and you added your own non-default constructor the instantiation will fail. I would suggest you to define the input file path as property like
@Value("${inputFilePath}")
.
Solution 1
Since you do not provide the public default constructor and you added your own non-default constructor the instantiation will fail. I would suggest you to define the input file path as property like @Value("${inputFilePath}")
.
If you need further initialization in your bean define a void method and annotate it with @PostConstruct
and do the initialization within.
Original Author schoener Of This Content
Solution 2
Add a public default constructor in your class. For example.
public User() {
}
Original Author vkstream Of This Content
Solution 3
Make sure you are using spring-boot-starter-data-jpa
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Original Author Kailas010 Of This Content
Solution 4
You defined something like this:
@Component
public class InputItemReader{
public InputItemReader(String input){
...
}
}
The name of your class suggest that your object is not a bean, just a simple object. You should try to use it in classic way:
new InputItemReader(myString);
or to have a static method to process the input String.
Explanation: Spring IoC container will try to instantiate a new InputItemReader object like this :
new InputItemReader( -- WHAT TO PUT HERE? --)
and will fail to call your constructor, because it will not know what you do actually expect and input string.
UPDATE:
Your problem can be solved by removing @Component annotation and defining the bean in a configuration like this:
@Bean
public InputItemReader inputItemReader(InputFileHeaderValidator inputFileHeaderValidator, FileAuditService fileAuditService){
InputItemReader inputItemReader = new InputItemReader("--HERE SHOULD BE ACTUAL PATH---");
// set the required service, a cleaner approach would be to send them via constructor
inputItemReader.setFilteAuditService(fileAuditService);
inputItemReader.setInputFileHeaderValidator(inputFileHeaderValidator);
return inputItemReader;
}
Original Author Adina Rolea Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.