运行spring boot应用程序
描述:
Car中构造函数的参数0需要类型为“java.lang.String”的bean,但该bean不能为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() {
}
}
发布于 2018-12-09 01:40:05
如果您想要将一个汽车对象作为组件注入,那么您应该提供它的参数,如String name和int Color,然后您可以通过以下步骤添加一些配置管理器:
@Configuration公共类ConfigurationManager { @Bean公共汽车car() { return new Car("Default",1);} }
发布于 2019-03-23 02:30:28
我也遇到过类似的问题。我将构造函数替换为getter和setter来赋值。它成功了..。
https://stackoverflow.com/questions/53684852
复制相似问题