Reputation: 474
Run spring boot application
Description:
Parameter 0 of constructor in Car required a bean of type 'java.lang.String' that could not be foun
@Component
public class Car implements Driver {
private String name;
private int color;
@Autowired
public Car(String name, int color) {
this.name = name;
this.color = color;
}
@Override
public void close() {
}
}
Upvotes: 4
Views: 33941
Reputation:
If you want to inject a Car object as component then you should provide its parameters like String name and int Color, then you might add on some configuration manager by following these steps:
Remove both @Component and @Autowired annotations.
Need to create a bean as shown on some configuration manager class as configuration.
@Configuration
public class ConfigurationManager {
@Bean
public Car car() {
return new Car("Default", 1);
}
}
Upvotes: 4
Reputation: 70
I have faced a similar issue. I replaced the constructor with getters and setters to assign the values. it worked..
Upvotes: 5