【问题标题】:LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the contextLifecycleProcessor 未初始化 - 在通过上下文调用生命周期方法之前调用“刷新”
【发布时间】:2015-08-06 08:48:25
【问题描述】:

我是 Spring Security 的新手,我已经完成了教程中的所有内容,但我遇到了这个异常。

我有一个简单的 Spring Security + JSF web 应用:

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>

spring-config.xml 为空。

这是我的依赖项:

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

但是当我运行应用程序时出现此异常:

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)

更新

【问题讨论】:

  • 用mvn dependency:tree检查你的依赖关系,确保你没有混合不同版本的spring jars。
  • Alt + F5 然后刷新项目。
  • @M.Deinum 我应该从存储库文件夹中删除旧版本的依赖项吗?例如,我在该文件夹中有三个版本的 spring,但我在项目中使用了最后一个版本。
  • 请发布输出而不是截图。您从某个随机目录执行它,您必须从您的项目目录执行mvn dependency:tree。
  • @M.Deinum 在应用程序的根路径中?

标签: spring jsf spring-security


【解决方案1】:

遇到了同样的问题。它是由结合使用 java 8 和一些 spring 依赖项引起的。还没弄清楚是哪个,但是当时使用java 7解决了这个问题。

【讨论】:

    【解决方案2】:

    使用正确版本的tomcat部署正确版本的spring及其依赖项, 例如 - Spring 3.2 with Jersey 2.22 in Tomcat 8 而不是 tomcat 7。 Tomcat 7 中带有 Jersey 2 的 Spring 3.0 查看版本兼容性

    【讨论】:

      【解决方案3】:

      如果您使用 Spring 并在项目属性中手动添加外部 Jar 而不是使用专用依赖文件“pom.xml”,则可能会出现此错误。

      【讨论】:

        【解决方案4】:

        对我来说,这是由引入不兼容依赖项的依赖项引起的。我不得不排除不必要的根依赖:

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

        【讨论】:

          【解决方案5】:

          我在我的项目中使用的是旧版本的 Tomcat,但我遇到了同样的错误。我将它更新到 Tomcat 9 并且它现在工作正常。您应该根据这些系统之间的兼容性来更新版本。

          【讨论】:

            【解决方案6】:

            在服务器中删除并重新添加项目帮助我解决了问题

            【讨论】:

            • 这样的建议适合评论而不是回答
            • @Gahan,名声较低导致我回答
            【解决方案7】:

            我最近也遇到了这个异常。对我来说,尝试在 Kubernetes 集群中部署 spring pod 时发生这种情况,在 spring 有机会正确启动并开始响应健康检查之前,pod 就被杀死了。

            对我来说,解决方法只是增加检查运行状况检查端点之前的延迟。

            如果您看到此错误,可能值得检查是否有什么东西在启动期间杀死了 spring

            【讨论】:

              【解决方案8】:

              我遇到了这个异常,在我的情况下,解决方案是在我的一个 DAO 实现中修复 @Repository("the typo is here") 标记中的错字

              【讨论】:

                猜你喜欢
                • 2011-10-06
                • 2017-10-14
                • 2017-11-24
                • 1970-01-01
                • 1970-01-01
                • 2020-02-03
                • 1970-01-01
                • 2015-06-22
                • 1970-01-01
                相关资源
                最近更新 更多