最初打开localhost网站选项卡时引发BeanInstantiationException和其他异常

问题描述

我通常对Vaadin和Spring Boot还是陌生的,所以最近,当我遇到这个问题时,我发现自己全神贯注地花了好几个小时不知道该怎么做。我已经在Google和这个论坛上进行了很多搜索,但是很多建议让我很困惑。

我的问题:

因此,我的网站是一个非常基本的天气应用程序,可以从免费的API获取信息。我的应用程序只有一页,它的根类“ MainLayout.java”类是Vertical布局,它向其自身添加了所有子布局/视图。我的问题是,执行以下操作后,此类的构造函数似乎给出了错误。

  1. 启动Spring-boot服务器(初始化正常,没有错误)
  2. 打开网站的标签,然后进入localhost:8080
  3. 发生错误,并显示堆栈跟踪,主要错误位于顶部

注意:有时,当我再次重新启动服务器并再次打开localhost:8080选项卡时,它将正常工作而没有错误。

给出了简短错误:

尝试使用导航到“”时发生异常 异常消息“使用名称创建bean时出错 'com.urweather.app.ui.layouts.MainLayout':通过Bean实例化 构造函数失败;嵌套异常为 org.springframework.beans.BeanInstantiationException:失败 实例化[com.urweather.app.ui.layouts.MainLayout]:构造函数 抛出异常;嵌套的异常是java.lang.IllegalStateException: 如果不锁定VaadinSession或UI,则无法访问状态 会话。”

具有构造函数的MainLayout类:

package com.urweather.app.ui.layouts;

import com.urweather.app.ui.views.NavigationView;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.PreserveOnRefresh;
import com.vaadin.flow.router.Route;

import org.springframework.beans.factory.annotation.Autowired;

@Route("")
@PageTitle("Ur Weather App")
@CssImport("./styles/shared-styles.css")
@PreserveOnRefresh
public class MainLayout extends VerticalLayout {

    private NavigationView searchBar;
    private CurrentInfoLayout currentInfoLayout;
    private MoreDetailInfoLayout moreDetailInfoLayout;

    @Autowired
    public MainLayout(NavigationView searchBar,CurrentInfoLayout currentInfoLayout,MoreDetailInfoLayout moreDetailInfoLayout) {
        this.searchBar = searchBar;
        this.currentInfoLayout = currentInfoLayout;
        this.moreDetailInfoLayout = moreDetailInfoLayout;
        addClassName("main-layout");

        add(this.searchBar,this.currentInfoLayout,this.moreDetailInfoLayout);
    }
}

注意:不同的Views / Layout类都使用@Component,其构造函数使用依赖项注入来注入后端服务等。

任何帮助将不胜感激!如果我需要提供有关此问题的更多信息,我们将很乐意提供。如果您对我应该寻找的东西甚至只有最小的提示,那我将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...