'Vaadin 23: ScopeNotActiveException at MainView, that extends AppLayout View

I have following Views structure:

Home Page

@SpringComponent
@UIScope
@PageTitle("ExampleApp: Home Page")
@Route(value = Endpoint.UI.HOME_PAGE, layout = MainView.class)
public class HomePage extends VerticalLayout {
  //the rest is ommited
}

few another pages like this and MainView:

@SpringComponent
@UIScope
@Push
@Viewport("width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes")
//@PWA - details ommited
@Theme(themeClass = Lumo.class, variant = Lumo.DARK)
@CssImport("./css/main_view.css")
public class MainView extends AppLayout implements BeforeEnterObserver, AppShellConfigurator {
   //implementation is ommited. 
}

In Vaadin 14.8.1 App works perfectly. But after updating to Vaadin 23.0.1 I got:


2022-03-14T09:39:07.191902382Z org.springframework.beans.factory.support.ScopeNotActiveException: Error creating bean with name 'mainView': 

Scope 'vaadin-ui' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton;

 nested exception is java.lang.IllegalStateException: There is no UI available. The UI scope is not active

Question: how do I access UI Scope or Object from MainView?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source