【发布时间】:2021-02-28 01:41:09
【问题描述】:
我正在尝试使用 mysql、spring 和 vaadin。 该应用程序应该访问数据库并在索引页面上显示表格
在代码中,我有扩展 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: 没有找到自动绑定的实例字段
【问题讨论】:
标签: mysql spring-boot spring-mvc vaadin javabeans