vendredi 27 février 2015

"Cannot initialize context because there is already a root app..." when a Jetty auto-restart occurs after a change in the code Spring Vaadin?

I am experiencing the following issue on a Spring application with Vaadin when I run it with Jetty:


I have Jetty configured in a way that it scans the project working directory and if it sees changes made in the code, it restarts the server automatically (like Tomcat does too).


What I noticed is that if I make even a small change in the code and then Jetty fires automatically a restart, the following exception is thrown:



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!



I know that this exception is thrown when there is more than one ContextLoaderListener as both ContextLoaderListeners try to load the same root ApplicationContext (therefore causing the exception), as explained here, also:


Why this Spring application with java-based configuration don't work properly


The point is that I do not have another ContextLoaderListener registered (or at least, I think so, as I cannot be sure cause I am using Spring together with Vaadin via the Vaadin Spring addon -> http://ift.tt/186xfcQ as a Maven dependency, and the addon is not yet officially STABLE).


One thing I am sure of is that the only listener I have in my code is the following:



package com.app.config;

import javax.servlet.annotation.WebListener;

import org.springframework.web.context.ContextLoaderListener;

@WebListener
public class AppContextLoaderListener extends ContextLoaderListener {
}


So I thought "Maybe there's a problem with the addon?". But then I tried to reproduce the issue using Tomcat instead of Jetty (started Tomcat, ran the application on Tomcat with Run on Server, modified some arbitrary code, waited that Tomcat republished the changes automatically) but the exception is never thrown with Tomcat.


So it might be Jetty related? Does anyone experienced something similar too?


Where is the issue?


This is the applicationContext.xml file I use (I post it for completeness):



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://ift.tt/GArMu6"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:context="http://ift.tt/GArMu7"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/18sW2ax
http://ift.tt/GArMu7 http://ift.tt/1tY3uA9">

<bean class="com.app.config.AppConfig" />
<context:component-scan base-package="com.app" />
</beans>

Aucun commentaire:

Enregistrer un commentaire