web-dev-qa-db-fra.com

LifecycleProcessor non initialisé - appelez 'refresh' avant d'appeler des méthodes de cycle de vie via le contexte

Je suis nouveau en sécurité au printemps, j'ai tout fait dans le tutoriel, mais j'ai cette exception.

J'ai une simple application Web Spring Security + JSF:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/security-config.xml</param-value>
    </context-param>

    <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>

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

     <!--JSF -->
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

security-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/security
       http://www.springframework.org/schema/security/spring-security.xsd">

    <security:http>
        <security:intercept-url pattern="/admin" access="ROLE_USER"/>
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="sajjad" password="414141" authorities="ROLE_USER"/>
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager>
</beans>

Le spring-config.xml est vide.

Voici mes dépendances:

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>


    <!-- Spring Security -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>4.0.1.RELEASE</version>
    </dependency>

Mais je reçois cette exception quand je lance l'application:

25-May-2015 02:35:11.113 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.Apache.catalina.core.StandardContext.startInternal Error listenerStart
25-May-2015 02:35:11.114 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.Apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
25-May-2015 02:35:11.125 WARNING [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.doClose Exception thrown from ApplicationListener handling ContextClosedEvent
 Java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Mon May 25 02:35:09 GMT+03:30 2015]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.Java:344)
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.Java:331)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.Java:869)
    at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.Java:836)
    at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.Java:579)
...

5-May-2015 02:35:11.127 WARNING [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.support.XmlWebApplicationContext.doClose Exception thrown from LifecycleProcessor on context close
 Java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Mon May 25 02:35:09 GMT+03:30 2015]; root of context hierarchy
    at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.Java:357)
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.Java:877)

METTRE &AGRAVE; JOUR

enter image description here

enter image description here

16
user4843183

Rencontré le même problème. Cela était dû à l’utilisation de Java 8 en combinaison avec certaines dépendances printanières. Je ne l'ai pas compris, mais l'utilisation de Java 7 a résolu le problème à l'époque.

12
Adrian B.

Vous pouvez avoir cette erreur si vous utilisez Spring et que vous ajoutez manuellement un conteneur externe dans les propriétés du projet au lieu d'utiliser le fichier de dépendance dédié "pom.xml".

4
Antoine Rougeot

Déployez la version correcte de spring et ses dépendances avec la version correcte de Tomcat, Par exemple - Spring 3.2 avec Jersey 2.22 dans Tomcat 8 et non dans Tomcat 7 . Spring 3.0 avec Jersey 2 dans Tomcat 7. compatibilité de version

4
hariharan kumar

Supprimer et rajouter le projet sur le serveur m’a aidé à résoudre le problème

1
M. Gopal

J'utilisais l'ancienne version de Tomcat pour mon projet et j'obtenais la même erreur. Je l'ai mis à jour pour Tomcat 9 et cela fonctionne bien maintenant. Vous devez mettre à jour la version en fonction de la compatibilité de ces systèmes.

1
Suketu

Pour moi, cela était dû à une dépendance qui introduisait une dépendance incompatible. Je devais exclure les dépendances root inutiles:

        <exclusions>
            <!-- Otherwise, Webapp doesn't start up -->
            <exclusion>
                <groupId>org.glassfish.jersey.containers</groupId>
                <artifactId>jersey-container-grizzly2-http</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.glassfish.jersey.ext</groupId>
                <artifactId>jersey-spring3</artifactId>
            </exclusion>
        </exclusions>
1
PAX

J'ai aussi rencontré cette exception récemment. Pour moi, cela se produisait lorsqu’on essayait de déployer une capsule de printemps dans un cluster de kubernetes, cette dernière était en train d’être tuée avant que le printemps ne puisse s’amorcer correctement et commencer à répondre au bilan de santé.

Pour moi, le correctif consistait simplement à augmenter le délai avant la vérification du point final Healthcheck.

Il peut être utile de vérifier si quelque chose tue le printemps au démarrage si vous voyez cette erreur

0
kane morgan