Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Spring integration on vaadin portlet
Hi,
I have a problem to integrate Spring in a vaadin portlet.
I use the method specified on the Spring Integration wiki page :
ServletContext servletContext = ((WebApplicationContext) application.getContext()).getHttpSession().getServletContext();
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
The error is :
java.lang.ClassCastException: com.vaadin.terminal.gwt.server.PortletApplicationContext2 cannot be cast to com.vaadin.terminal.gwt.server.WebApplicationContext
Thanks.
In fact, with portlet 2.0 support, the PortletApplicationContext2 inherites directly from AbstractWebApplicationContext class.
The PortletApplicationContext (portlet before version 6.2) inherites from WebApplicationContext which inherites from AbstractWebApplicationContext.
Why this change ?
I have try to go up in inheritance tree but with AbstractWebApplicationContext, i haven't succeed to get session object.
When using Portlet 1.0 portlets, there is a servlet behind the portlet and using the servlet context makes sense. However, a Portlet 2.0 portlet does not use a servlet at all, so many parts of the servlet API would not make any sense.
You should use the Spring PortletApplicationContextUtils.
The code snippet could look something like:
PortletContext portletContext = ((PortletApplicationContext2) application.getContext()).getPortletSession().getPortletContext();
context = PortletApplicationContextUtils.getRequiredWebApplicationContext(portletContext);