I started recently a project with the Spring framework with the ojective to develop it without none XML config file, only Java code.
In this current moment, I add th
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!
In your WebAppInitializer
, you are registering a ContextLoaderListener
.
Because you are using AbstractSecurityWebApplicationInitializer
with the super
constructor that accepts a Class[]
Creates a new instance that will instantiate the ContextLoaderListener with the specified classes.
that also registers a ContextLoaderListener
. Note the class javadoc
When used with
AbstractSecurityWebApplicationInitializer(Class...)
, it will also register aContextLoaderListener
. When used withAbstractSecurityWebApplicationInitializer()
, this class is typically used in addition to a subclass ofAbstractContextLoaderInitializer
.
As the error states, you cannot have two ContextLoaderListener
instances because they will both try to create and add a ApplicationContext
to the ServletContext
.