Spring Session安全配置和多个contextLoaderListener类异常

时间:2016-05-09 10:39:15

标签: spring-mvc spring-session

我正在尝试将Spring Session 1.2.0集成到已配置Spring Security的现有Spring MVC项目中。

我根据这些进行了配置:

http://docs.spring.io/spring-session/docs/1.2.0.BUILD-SNAPSHOT/reference/html5/guides/security.html

http://docs.spring.io/spring-session/docs/1.2.0.BUILD-SNAPSHOT/reference/html5/guides/httpsession-jdbc.html

但是,我无法在tomcat上部署应用程序,因为我一直处于异常状态:

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 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! at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:277) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1879) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

存在相关问题Why this Spring application with java-based configuration don't work properly

如何在不创建ContextLoaderListener的新实例的情况下配置Spring Session?

1 个答案:

答案 0 :(得分:0)

我已经有了Spring Security配置。为了解决我的问题,我将注释@EnableJdbcHttpSession放在现有配置中,并确保配置了数据源和转换管理器。