Vaadin Spring integration

I’m using Vaadin 14.1.
I annotated my config class with @EnableVaadin({“axioma.web”}.
I don’t use SpringBoot.
When I start my application Spring starts and many bean are created.
However my home page, annotated as @Route{“”} doesn’t seem to be created as a Spring Bean and @Autowired doesn’t work.
Then my onshow event fail because of the lack of autowired components.
What did I forget ?
Tks
Tullio

@EnableVaadin is only effective together with Spring Boot. In other cases, you need to follow the steps defined in https://vaadin.com/docs/v14/flow/spring/tutorial-spring-basic-mvc.html to hook things up.

I tryed but it didn’t work.
I cancelled the @EnableVaadin annotation.
I created the following class (create is it enough ?).
Spring starts as usual but aganin my @Route is not a bean.
Tks four your help

package axioma.web.template.ui.app;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class TemplateServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

public TemplateServletInitializer() {
	super();
}

@Override
protected Class<?>[] getRootConfigClasses() {
	return null;
}

@Override
protected Class<?>[] getServletConfigClasses() {
	return null;
}

@Override
protected String[] getServletMappings() {
	return null;
}

}

I tried to add a class to getRootConfigClass but I get
java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!
Then I removed the SpringConfiguration from web.xml and it started again but the @Route problem is there.
Tks

Following indication in the link now I’m able to start my application with Spring.
Now my @Route is a Spring bean.
But the autowiring mechanism indicate that my session bean can’t be created because no session is active in the thread.
Why ?
I tried to annotate my @Route as @UIScope and as @Scope(“session”) but I got allways the same result.
Tks

Tullio Bettinazzi:
But the autowiring mechanism indicate that my session bean can’t be created because no session is active in the thread.

In what thread?

Spring’s native session scope is only active on the thread that processes a HTTP request. Vaadin’s custom session scope is only active on the thread that handles a HTTP request targeted to Vaadin, or for code that is running inside a UI.access callback.

I don’t know, in the thread processing my request.
I created a @Route(“”) and @Autowired a @Scope(“session”) bean, but it didn’t work.
Tks

Could you share the exact error message and the full exception stacktrace? That could make it easier to pinpoint what kind of thread it is and exactly what goes wrong.

Here the error
Tks

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘homePage’: Unsatisfied dependency expressed through field ‘funzioneMenuService’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘funzioneMenuServiceImpl’: Scope ‘session’ 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 thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1422) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:359) at com.vaadin.flow.spring.scopes.BeanStore.doGet(BeanStore.java:127) at com.vaadin.flow.spring.scopes.BeanStore.lambda$get$0(BeanStore.java:71) at com.vaadin.flow.spring.scopes.BeanStore.execute(BeanStore.java:135) at com.vaadin.flow.spring.scopes.BeanStore.get(BeanStore.java:71) at com.vaadin.flow.spring.scopes.AbstractScope.get(AbstractScope.java:44) at com.vaadin.flow.spring.scopes.VaadinUIScope.get(VaadinUIScope.java:42) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:356) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:227) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1155) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:416) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:349) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:342) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1126) at com.vaadin.flow.spring.SpringInstantiator.getOrCreate(SpringInstantiator.java:106) at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:158) at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:127) at java.util.Optional.orElseGet(Optional.java:267) at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:126) at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.createChain(AbstractNavigationStateRenderer.java:314) at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:195) at com.vaadin.flow.router.Router.handleNavigation(Router.java:223) at com.vaadin.flow.router.Router.navigate(Router.java:194) at com.vaadin.flow.router.Router.initializeUI(Router.java:92) at com.vaadin.flow.server.BootstrapHandler.createAndInitUI(BootstrapHandler.java:1489) at com.vaadin.flow.server.BootstrapHandler.synchronizedHandleRequest(BootstrapHandler.java:459) at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40) at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1540) at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:247) at com.vaadin.flow.spring.SpringServlet.service(SpringServlet.java:95) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1639) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘funzioneMenuServiceImpl’: Scope ‘session’ 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 thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:368) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1287) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640) … 58 common frames omitted Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request. at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131) at org.springframework.web.context.request.SessionScope.get(SessionScope.java:55) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:356) … 63 common frames omitted