ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the cont

今天遇到了这个问题,一启动Spring boot就报这个错误:

Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@359f7cdf: startup date [Thu Nov 30 17:18:38 CST 2017]; root of context hierarchy

而且线索很模糊,不知道哪里出了问题。
所有类zip,只剩下启动用的main函数同错。

看到这位csdn博客 的经验:
不同的组件有相同的bean名称。虽然我高度怀疑,因为经验告诉我有相同bean名称的会抛一个类似“已经有一个bean xxx”的错误。
代码只剩下main函数,所以高度怀疑是pom.xml冲突。但是哪个冲突呢,如果用mvn dependency:tree分析,太耗时。
想起

@RunWith(SpringRunner.class)
@SpringBootTest
public class XXXTest 用的spring的上下文是不同的,于是写了个空的UT。执行时报:
 o.s.test.context.TestContextManager      : Caught exception while allowing TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener@b59d31] to prepare test instance [com.example.demosm.DemoSmApplicationTests@4acf72b6]

java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
    at org.springframework.data.redis.repository.configuration.RedisRepositoryConfigurationExtension.registerBeansForRoot(RedisRepositoryConfigurationExtension.java:88) ~[spring-data-redis-2.0.2.RELEASE.jar:2.0.2.RELEASE]

一眼看到redis。再用mvn dependency:tree 发现果然spring-data-redis的包被引了两遍,并且是不同版本。删除其中一个,问题解决。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值