Spring Boot启动时报错ApplicationEventMulticaster not initialized - call ‘refresh‘

情景

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

问题解决!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`refresh()` 是 Spring 框架中的一个方法,它用于刷新应用程序上下文(ApplicationContext)以更新其内部状态。在 Spring 框架中,`refresh()` 方法是非常重要的,因为它负责完成应用程序上下文的初始化和配置,并准备好所有的单例 bean 以供使用。 下面是 `refresh()` 方法的主要流程: 1. 准备刷新过程中需要用到的变量和标志位; 2. 调用 `prepareRefresh()` 方法,进行一些预处理工作; 3. 调用 `obtainFreshBeanFactory()` 方法,创建 BeanFactory 并进行一些初始化工作; 4. 调用 `prepareBeanFactory(beanFactory)` 方法,对 BeanFactory 进行一些后续处理; 5. 调用 `postProcessBeanFactory(beanFactory)` 方法,对 BeanFactory 进行后置处理; 6. 调用 `invokeBeanFactoryPostProcessors(beanFactory)` 方法,执行 BeanFactoryPostProcessor 的 postProcessBeanFactory() 方法; 7. 调用 `registerBeanPostProcessors(beanFactory)` 方法,注册 BeanPostProcessor 实例; 8. 调用 `initMessageSource()` 方法,初始化 MessageSource 组件; 9. 调用 `initApplicationEventMulticaster()` 方法,初始化 ApplicationEventMulticaster 组件; 10. 调用 `onRefresh()` 方法,进行一些自定义的刷新工作; 11. 调用 `registerListeners()` 方法,注册事件监听器; 12. 调用 `finishBeanFactoryInitialization(beanFactory)` 方法,完成所有非延迟初始化的单例 bean 的初始化工作; 13. 调用 `finishRefresh()` 方法,完成上下文的刷新工作。 需要注意的是,`refresh()` 方法在执行过程中会涉及到很多细节,比如如何处理环境变量、如何处理自定义的 bean 定义、如何处理多个上下文之间的关系等等。如果需要深入了解 `refresh()` 方法的实现细节,可以查看 Spring 框架的源代码。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值