如何解决最初打开localhost网站选项卡时引发BeanInstantiationException和其他异常
我通常对Vaadin和Spring Boot还是陌生的,所以最近,当我遇到这个问题时,我发现自己全神贯注地花了好几个小时不知道该怎么做。我已经在Google和这个论坛上进行了很多搜索,但是很多建议让我很困惑。
我的问题:
因此,我的网站是一个非常基本的天气应用程序,可以从免费的API获取信息。我的应用程序只有一页,它的根类“ MainLayout.java”类是Vertical布局,它向其自身添加了所有子布局/视图。我的问题是,执行以下操作后,此类的构造函数似乎给出了错误。
- 启动Spring-boot服务器(初始化正常,没有错误)
- 打开网站的标签,然后进入localhost:8080
- 发生错误,并显示堆栈跟踪,主要错误位于顶部
注意:有时,当我再次重新启动服务器并再次打开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 举报,一经查实,本站将立刻删除。