org.springframework.beans.factory.BeanCreationException:创建名称为“”的 bean 时出错:通过构造函数实例化 Bean 失败;

org.springframework.beans.factory.BeanCreationException: Error creating bean with name '': Bean instantiation via constructor failed;

我正在尝试使用 mysql、spring 和 vaadin。 该应用程序应访问数据库并在索引页

上显示 table

在代码中,我有扩展 jparepository 的接口存储库, 服务:

public class UtenteService {
    private UtenteRepository utenterep;
    
    public UtenteService(UtenteRepository utenterepository){
        this.utenterep=utenterepository;
    }
    public List<Utente> findAll(){
        return this.utenterep.findAll();
    }
    public void  save(Utente u){
        if(u==null){
            return;
        }
        utenterep.save(u);
    }
}

以及我调用服务的视图:

public class HelloView extends HorizontalLayout implements AfterNavigationObserver {
    
    @Autowired
    private UtenteService utenteService;
    
    private TextField name;
    private Button sayHello;
    private Grid<Utente> utenti = new Grid<>(Utente.class);
    private Binder<Utente> binder;

    


    public HelloView(UtenteService utenteService1) {
        this.utenteService=utenteService1;
        HorizontalLayout hor = new HorizontalLayout();
        setId("hello-view");
        name = new TextField("Your name");
        sayHello = new Button("Say hello");
        setVerticalComponentAlignment(Alignment.END, name, sayHello);
        sayHello.addClickListener( e-> {
            Notification.show("Hello " + name.getValue());
        });
        hor.add(name, sayHello);
        add(hor);
        configureGrid();
        hor.add(utenti);
        updategrid();
    }



    private void updategrid() {
        // TODO Auto-generated method stub
        utenti.setItems(utenteService.findAll());
    }



    private void configureGrid() {
        utenti.setSizeFull();
        utenti.setColumns("id","nome","password","id_ruolo");
        
        binder = new Binder<>(Utente.class);
        binder.bindInstanceFields(this);
        binder.setBean(new Utente());
        
        
    }

    @Override
    public void afterNavigation(AfterNavigationEvent event) {
        // TODO Auto-generated method stub
        utenti.setItems(utenteService.findAll());
        
    }  

错误

org.springframework.beans.factory.BeanCreationException:创建名称为 'it.tirocinio.application.views.hello.HelloView' 的 bean 时出错:通过构造函数实例化 Bean 失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [it.tirocinio.application.views.hello.HelloView]:构造函数抛出异常;嵌套异常是 java.lang.IllegalStateException: 没有找到自动绑定的实例字段

通常最后一个错误是根本原因,应该有一个堆栈跟踪显示错误发生的位置。

查看您发布的文本中的最后一个错误,您会看到 java.lang.IllegalStateException: There are no instance fields found for automatic binding

所以错误很可能是因为您正在调用 bindInstanceFields(this),但是没有匹配的字段。您的实体 Utente 有一个字段 nome,但在 HelloView 中它被称为 name