情景
Spring Boot启动时报错 ApplicationEventMulticaster not initialized - call ‘refresh’ before multicasting events via the context
控制台打印的消息如下、所示
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2d3ef181: startup date [Sat Oct 10 09:18:21 CST 2020]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@511816c0
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:414) ~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE]
……
意为:ApplicationEventMulticaster未初始化 - 在通过上下文组播事件之前调用’刷新’
原因
原来运行调试正常的项目,在今天启动Debug模式的时候报出了这个错误:
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized
多次从网上搜索之可以将可以看到的错误总结如下:
1)Jar包相关的问题:查看是否缺少spring jar包,缺少的话加上;查看jar包是否冲突删除冲突jar包;有时候由于导入过程中jar包保存不完全造成的,将lib下jar包全部删除重新导入。
2)复制类的时候,注解的name命名重复例如复制之后出现的@Service("psfService")
标签重复
定位错误
而我根据第二个错误,并阅读控制台打印的错误提示发现我的错误提示部分是
org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
网上大部分错误都是
org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster
于是我逐渐找到之前更改的内容,也就是从自定义yml文件中获取属性的一个方法,编写错误
@Data
@Component
@ImportResource("classpath:readStandard.yml")
@ConfigurationProperties(prefix = "url")
public class UrlForenConfig {
private String resObjectUrl;
private String resCfgUrl;
}
更改为:
@Data
@ConfigurationProperties(prefix = "url")
@PropertySource(value = "classpath:readStandard.yml")
@Component
public class UrlForenConfig {
@Value("${resObjectUrl}")
private String resObjectUrl;
@Value("${resCfgUrl}")
private String resCfgUrl;
}
问题解决!