今天遇到了这个问题,一启动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的包被引了两遍,并且是不同版本。删除其中一个,问题解决。