web-dev-qa-db-fra.com

Exception d'envoi d'un événement initialisé dans un contexte avec l'instance d'écoute de la classe org.springframework.web.context.ContextLoaderListener

J'essaie d'implémenter le journal de sécurité Spring et j'ai essayé quelque chose comme:

spring-security.xml:
<beans:beans xmlns="http://www.springframework.org/schema/security"
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <http auto-config="true"  use-expressions="true">
        <intercept-url pattern="/login" access="permitAll" />
        <intercept-url pattern="/logout" access="permitAll" />
        <intercept-url pattern="/accessdenied" access="permitAll" />
        <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
        <form-login login-page="/login" default-target-url="/list" authentication-failure-url="/accessdenied" />
        <logout logout-success-url="/logout" />
    </http>

    <authentication-manager alias="authenticationManager">
        <authentication-provider>
            <user-service>
                <user name="lokesh" password="password" authorities="ROLE_USER" />
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

web.xml:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
           org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring-servlet.xml,
            /WEB-INF/spring-security.xml
        </param-value>
    </context-param>

 <listener>  
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
 </listener>  



 <!-- Spring Security -->  
 <filter>  
  <filter-name>springSecurityFilterChain</filter-name>  
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
 </filter>  

 <filter-mapping>  
  <filter-name>springSecurityFilterChain</filter-name>  
  <url-pattern>/*</url-pattern>  
 </filter-mapping>  

J'utilise la version de printemps: 3.1 et je reçois l'erreur dans le fichier XML ci-dessus.

erreur:

May 5, 2014 12:33:47 PM org.Apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/spring-security.xml]; nested exception is Java.lang.NoClassDefFoundError: org/springframework/security/web/util/AntPathRequestMatcher
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.Java:412)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.Java:334)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.Java:302)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.Java:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.Java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.Java:180)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.Java:125)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.Java:94)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.Java:131)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.Java:522)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:436)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.Java:377)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.Java:278)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.Java:111)
    at org.Apache.catalina.core.StandardContext.listenerStart(StandardContext.Java:3843)
    at org.Apache.catalina.core.StandardContext.start(StandardContext.Java:4350)
    at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1045)
    at org.Apache.catalina.core.StandardHost.start(StandardHost.Java:719)
    at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1045)
    at org.Apache.catalina.core.StandardEngine.start(StandardEngine.Java:443)
    at org.Apache.catalina.core.StandardService.start(StandardService.Java:516)
    at org.Apache.catalina.core.StandardServer.start(StandardServer.Java:710)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:578)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:39)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25)
    at Java.lang.reflect.Method.invoke(Method.Java:597)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:288)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:413)
Caused by: Java.lang.NoClassDefFoundError: org/springframework/security/web/util/AntPathRequestMatcher
    at org.springframework.security.config.http.MatcherType.<clinit>(MatcherType.Java:22)
    at org.springframework.security.config.http.HttpConfigurationBuilder.<init>(HttpConfigurationBuilder.Java:105)
    at org.springframework.security.config.http.HttpSecurityBeanDefinitionParser.createFilterChain(HttpSecurityBeanDefinitionParser.Java:116)
    at org.springframework.security.config.http.HttpSecurityBeanDefinitionParser.parse(HttpSecurityBeanDefinitionParser.Java:81)
    at org.springframework.security.config.SecurityNamespaceHandler.parse(SecurityNamespaceHandler.Java:88)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.Java:1414)
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.Java:1404)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.Java:184)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.Java:140)
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.Java:111)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.Java:493)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.Java:390)
    ... 28 more
May 5, 2014 12:33:47 PM org.Apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
May 5, 2014 12:33:47 PM org.Apache.catalina.core.StandardContext start
SEVERE: Context [/HRportal] startup failed due to previous errors
May 5, 2014 12:33:47 PM org.Apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
May 5, 2014 12:33:47 PM org.Apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
Java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
    at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.Java:172)
    at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.Java:1066)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.Java:1040)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.Java:988)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.Java:534)
    at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.Java:142)
    at org.Apache.catalina.core.StandardContext.listenerStop(StandardContext.Java:3882)
    at org.Apache.catalina.core.StandardContext.stop(StandardContext.Java:4516)
    at org.Apache.catalina.core.StandardContext.start(StandardContext.Java:4380)
    at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1045)
    at org.Apache.catalina.core.StandardHost.start(StandardHost.Java:719)
    at org.Apache.catalina.core.ContainerBase.start(ContainerBase.Java:1045)
    at org.Apache.catalina.core.StandardEngine.start(StandardEngine.Java:443)
    at org.Apache.catalina.core.StandardService.start(StandardService.Java:516)
    at org.Apache.catalina.core.StandardServer.start(StandardServer.Java:710)
    at org.Apache.catalina.startup.Catalina.start(Catalina.Java:578)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:39)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:25)
    at Java.lang.reflect.Method.invoke(Method.Java:597)
    at org.Apache.catalina.startup.Bootstrap.start(Bootstrap.Java:288)
    at org.Apache.catalina.startup.Bootstrap.main(Bootstrap.Java:413)

Quelqu'un peut-il me corriger, je me trompe quelque part?

9
user3448105

spring-security-web-3.1.X.RELEASE.jar vous manque dans votre classpath

Si vous êtes certain de ne pas avoir bousillé le pot, nettoyez le projet et exécutez mvn clean install. Cela devrait résoudre le problème.

0
Naresh

Cela se produit s’il existe deux autres variables ContextLoaderListener dans votre projet.

Par exemple, dans mon cas, 2 ContextLoaderListener existait en utilisant 

  1. Configuration java 
  2. web.xml 

Supprimez donc toute variable ContextLoaderListener de votre projet et exécutez votre application.

0
dnyaneshwar