xpoft / spring-vaadin

Spring and Vaadin integration
Other
55 stars 44 forks source link

troubles using more than one SpringVaadinServlet with different contextConfiguration #39

Open maslovalex opened 10 years ago

maslovalex commented 10 years ago

If I define few SpringVaadinServlets in my war with different "contextConfiguration" only one of them works. I guess the reason is static nature of SpringApplicationContext.

public class SpringApplicationContext implements Serializable
{
    private static transient ApplicationContext applicationContext;

    public static void setApplicationContext(ApplicationContext applicationContext)
    {
        SpringApplicationContext.applicationContext = applicationContext;
    }

    public static ApplicationContext getApplicationContext()
    {
        return applicationContext;
    }
}

It is set in SpringVaadinServlet/Portlet.init(...) and used later in different places.

But when you have more than one Servlet defined in web.xml, the applicationContext in SpringApplicationContext is overridden by the last initialized servlet.

As a result only one servlet gets correct ApplicationContext. Others have to use in too, and it means NoSuchBeanDefinitionException...

pure static evil :)

Milbor-zz commented 9 years ago

We ran into this issue during portlet development. Each portlet is required to specify it's own contextConfigLocation. However because of the nature of ru.xpoft.vaadin.SpringApplicationContext, only one application context is registered for whole application. One thought how to solve this is to use map of contexts instead. Keys could be servlet/portlet names as they are available in VaadinServletService and VaadinPortletService, e.g. ((VaadinServletService) VaadinService.getCurrent()).getServlet().getServletName().

@xpoft any plans to look into this? Because of time constraint on our project we will implement the fix locally.