spring LifecycleProcessor 未初始化 - 在通过上下文调用生命周期方法之前调用“刷新”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30428725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context
提问by
I am new in spring security I have been done everything in tutorial, but i got this exception.
我是 Spring Security 的新手我已经完成了教程中的所有内容,但是我遇到了这个例外。
I have a simple Spring Security + JSF web app:
我有一个简单的 Spring Security + JSF Web 应用程序:
web.xml
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
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>
The spring-config.xml
is empty.
该spring-config.xml
是空的。
Here is my dependencies:
这是我的依赖项:
<!-- 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>
But i get this exception when i run the 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)
UPDATE
更新
回答by Adrian B.
Encountered the same problem. It was caused by using java 8 in combination with some spring dependencies. Haven't figured it out which, but using java 7 solved the problem at the time.
遇到了同样的问题。它是由结合使用 java 8 和一些 spring 依赖项引起的。还没有弄清楚是哪个,但当时使用 java 7 解决了这个问题。
回答by Antoine Rougeot
You can have this error if you use Spring and you add an External Jar manually in the project properties instead of using the dedicated dependency file "pom.xml".
如果您使用 Spring 并在项目属性中手动添加外部 Jar 而不是使用专用的依赖文件“pom.xml”,则可能会出现此错误。
回答by hariharan kumar
Deploy right version of spring and its dependencies with right version of tomcat, for eg - Spring 3.2 with Jersey 2.22 in Tomcat 8 and not in tomcat 7. Spring 3.0 with Jersey 2 in tomcat 7 See the version compatibility
使用正确版本的 tomcat 部署正确版本的 spring 及其依赖项,例如 - 在 Tomcat 8 中使用 Jersey 2.22 而不是在 tomcat 7 中的 Spring 3.2。在 tomcat 7 中使用 Jersey 2 的 Spring 3.0 查看版本兼容性
回答by PAX
For me it was caused by a dependency which introduced an incompatible dependency. I had to exclude the unnecessary root dependencies:
对我来说,这是由引入不兼容依赖项的依赖项引起的。我不得不排除不必要的根依赖项:
<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>
回答by suketup
I was using older version of Tomcat for my project and I was getting same error. I updated it to Tomcat 9 and its working fine now. You should update version as per compatibility of those systems with each other.
我在我的项目中使用了旧版本的 Tomcat,但我遇到了同样的错误。我将其更新为 Tomcat 9,现在工作正常。您应该根据这些系统彼此的兼容性更新版本。
回答by M. Gopal
Removing and re adding the project in the server helped me to solve the issue
在服务器中删除并重新添加项目帮助我解决了问题
回答by kane morgan
I also ran into this exception recently. For me it was happening when trying to deploy a spring pod in a kubernetes cluster, the pod was being killed before spring had a chance to boot up properly and start responding to the health check.
我最近也遇到了这个异常。对我来说,当尝试在 kubernetes 集群中部署 spring pod 时发生了这种情况,在 spring 有机会正确启动并开始响应健康检查之前,pod 被杀死了。
The fix for me was just to increase the delay before checking the healthcheck endpoint.
对我来说,修复只是在检查健康检查端点之前增加延迟。
It may be worth checking if something is killing spring during startup if you're seeing this error
如果您看到此错误,可能值得检查在启动期间是否有什么东西在杀死 spring
回答by OriginalUsername
I came across this exception and in my case the solution was fixing a typo in a @Repository("the typo was here") tag in one of mine DAO implementations
我遇到了这个异常,在我的情况下,解决方案是在我的一个 DAO 实现中修复 @Repository("the Tyre was here") 标签中的错字