BeanInstantiationException and other exceptions thrown when initially openi

Hello, I am fairly new to Vaadin and spring boot in general so recently, when I got this issue, I found myself racking my brain for hours on end not having a clue to what to do. I’ve done many searches on google and on this forum but I’m fairly confused by many of the recommendations.

My Issue:
So my website is a very basic weather application that gets information from free APIs. My application is only one page and its root class “MainLayout.java” class is a Vertical layout that adds all the children layouts/views to itself. My issue is that the constructor for this class seems to be giving an error after I do the following.

  1. Start up Spring-boot server (It initializes fine, no errors)
  2. Open up a tab of the website and go on localhost:8080
  3. Error occurs and a stack trace is shown with the main errors on top

NOTE: Sometimes when I restart the server again and open the localhost:8080 tab again, it will just work with no errors.

Short Error Given:
There was an exception while trying to navigate to ‘’ with the exception message ‘Error creating bean with name ‘com.urweather.app.ui.layouts.MainLayout’: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.urweather.app.ui.layouts.MainLayout]
: Constructor threw exception; nested exception is java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.’

MainLayout class that has the constructor:

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);
    }
}

Note: The different Views/Layout classes all use @Component and their constructors use dependency injection to get inject backend services, etc.

ANY help would be greatly appreciated! If I need to provide any more information regarding this issue then I will gladly do so. If you have even the smallest hint as to what I should be looking for then I will greatly appreciate that.

Corresponding case already resolved on [Stack Overflow]
(https://stackoverflow.com/questions/63492784/beaninstantiationexception-and-other-exceptions-thrown-when-initially-opening-lo). The core of the case is that @UISope or @Scope("prototype") is needed when a component is explicitly marked as a Spring bean.