java.lang.IllegalState 异常 LifecylceProcessor 和 ApplicationEventMulticaster 在使用 Spring Boot 时未初始化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26238505/
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
java.lang.IllegalState Exception LifecylceProcessor and ApplicationEventMulticaster not initialized when using Spring Boot
提问by mangusbrother
I have created a spring boot wrapper class as follows:
我创建了一个 spring boot 包装类,如下所示:
package package.for;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class AppBooter {
public static void main(String args[]){
SpringApplication.run("path/to/context.xml", args);
System.out.println("============ done");
do{
}while(true);
}
}
context.xml contains the bean pointing to the main class as follows:
context.xml 包含指向主类的 bean,如下所示:
<bean id="starter" class="package.for.AppBooter" />
as well as several other beans I require.
以及我需要的其他几种豆子。
As for dependencies I have the following:
至于依赖项,我有以下几点:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>1.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.1.7.RELEASE</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId> wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>opensymphony</groupId>
<artifactId>sitemesh</artifactId>
<version>2.5</version>
</dependency>
However when I run I get the following exceptions:
但是,当我运行时,出现以下异常:
Exception in thread "main" 2014-10-07 16:12:54.267 INFO 4616 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6c4cbf96: startup date [Tue Oct 07 16:12:50 CEST 2014]; root of context hierarchy
java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationDelegate.<init>(Lorg/springframework/data/repository/config/RepositoryConfigurationSource;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;)V
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:58)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:319)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:139)
at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:324)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:608)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:463)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:952)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:941)
at package.for.AppBooter.main(AppBooter.java:12)
2014-10-07 16:12:54.303 WARN 4616 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Exception thrown from ApplicationListener handling ContextClosedEvent
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6c4cbf96: startup date [Tue Oct 07 16:12:50 CEST 2014]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:345)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:332)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:879)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:141)
at org.springframework.context.support.AbstractApplicationContext.run(AbstractApplicationContext.java:808)
2014-10-07 16:12:54.304 WARN 4616 --- [ Thread-1] ationConfigEmbeddedWebApplicationContext : Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6c4cbf96: startup date [Tue Oct 07 16:12:50 CEST 2014]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:358)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:887)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.doClose(EmbeddedWebApplicationContext.java:141)
at org.springframework.context.support.AbstractApplicationContext.run(AbstractApplicationContext.java:808)
As for how I am packaging the jar here is the plugin snippet:
至于我如何打包 jar 是插件片段:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>package.for.AppBooter</mainClass>
</configuration>
<version>1.1.5.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions
</plugin>
采纳答案by mangusbrother
This was solved by upgrading spring-web and spring-webmvc dependencies to 4.0.7.RELEASE
这是通过将 spring-web 和 spring-webmvc 依赖项升级到 4.0.7.RELEASE 解决的
回答by Andy Wilkinson
I think the root cause of the problem is a NoSuchMethodError
:
我认为问题的根本原因是NoSuchMethodError
:
java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationDelegate.<init>(Lorg/springframework/data/repository/config/RepositoryConfigurationSource;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;)V
at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:58)
You haven't posted any details of your Spring Data dependencies, but looks like you're trying to use a version of one of the Spring Data projects that isn't compatible with the version of Spring Boot that you're using. Spring Boot provides dependency management for then entire Spring Data release train so your best option is probably to just remove the version from any Spring Data dependencies in your pom and let Spring Boot's dependency management take control of the version.
您尚未发布 Spring Data 依赖项的任何详细信息,但看起来您正在尝试使用与您正在使用的 Spring Boot 版本不兼容的 Spring Data 项目之一的版本。Spring Boot 为整个 Spring Data 发布系列提供依赖管理,因此您最好的选择可能是从 pom 中的任何 Spring Data 依赖项中删除版本,并让 Spring Boot 的依赖项管理控制该版本。
回答by Mehdi Raza
I was facing this error and I had already 4.3.2.RELEASE for spring-web and spring-web-mvc.
我遇到了这个错误,而且我已经有了 spring-web 和 spring-web-mvc 的 4.3.2.RELEASE。
It is solved, this was due to defining spring-data-releasetrain. Removing that solved the problem.
解决了,这是由于定义了spring-data-releasetrain。删除它解决了问题。
回答by Doug
Had same issue and was not dependencies related.
有同样的问题,并且与依赖关系无关。
I had the following code:
我有以下代码:
@Configuration
public class ConfigurationClass {
private final MyProperties MY_PROPERTIES;
ConfigurationClass(MyProperties myProperties) {
this.MY_PROPERTIES = myProperties
}
@Bean
@LoadBalanced
public RestTemplate testRestTemplate(RestTemplateBuilder builder) {
return builder.setConnectTimeout(MY_PROPERTIES.getTimeout()).build();
}
}
Changing it to the following made it work:
将其更改为以下内容使其工作:
@Configuration
public class ConfigurationClass {
@Bean
@LoadBalanced
public RestTemplate testRestTemplate(RestTemplateBuilder builder,
MyProperties myProperties) {
return builder.setConnectTimeout(myProperties.getTimeout()).build();
}
}
I am not sure why this was causing an issue though. Maybe you can't use constructor injection when you want to use it inside beans. Hope someone can answer in the comments
我不确定为什么这会导致问题。当你想在 bean 中使用它时,也许你不能使用构造函数注入。希望有人能在评论中回答