When I add @Route to my class I can use Springs Dependency Injection.
BUT I cannot get the Bean from the ApplicationContext because it’s not registered as Bean.
If I add @Component to a @Route to make it a Spring bean I get:
Caused by: java.lang.IllegalStateException: No VaadinSession bound to current thread
at com.vaadin.flow.spring.scopes.AbstractScope.getVaadinSession(AbstractScope.java:75)
My questions:
How is the Spring Integration done?
How can I get a Route from the Spring ApplicationContext?
Regarding your second question, the Router (ui.getRouter()) allows to inspect the declared routes. You can also declare Routes as actual spring beans, and in that case they would be both spring-managed and available as navigation targets.
But the the answer to the 2. question doesn’t work.
If I add @Component to my @Route I get the above exception. I have to mention that my Route is @UIScope
Is this a problem?
When is that exception raised? It’s correct to add @UIScoped, because otherwise they would be singletons (which is not correct because each time the user navigates into a view, a new instance has to be created).
The application does not start when I add @Component to the route class.
jooqRepository is also UIScoped
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jooqRepository': 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: No VaadinSession bound to current thread
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:365) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1248) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1168) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
... 24 common frames omitted
Caused by: java.lang.IllegalStateException: No VaadinSession bound to current thread
at com.vaadin.flow.spring.scopes.AbstractScope.getVaadinSession(AbstractScope.java:75) ~[vaadin-spring-11.0.0.jar:na]
at com.vaadin.flow.spring.scopes.VaadinUIScope.getBeanStore(VaadinUIScope.java:121) ~[vaadin-spring-11.0.0.jar:na]
at com.vaadin.flow.spring.scopes.AbstractScope.get(AbstractScope.java:44) ~[vaadin-spring-11.0.0.jar:na]
at com.vaadin.flow.spring.scopes.VaadinUIScope.get(VaadinUIScope.java:42) ~[vaadin-spring-11.0.0.jar:na]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353) ~[spring-beans-5.1.7.RELEASE.jar:5.1.7.RELEASE]
... 29 common frames omitted