mysql scope runtime_Maven依赖scope属性详解-一个报错引发的问题 - 老郭种树

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

今天从Github下载一个spring boot项目,运行后报如上错误,详细如下:

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@63f509: startup date [Wed Jun 21 17:07:06 EDT 2017]; root of context hierarchy at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404) [spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:954) [spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:961) [spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033) [spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555) [spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE] at SpringBootExample.main(SpringBootExample.java:12) [classes/:na]

二、

1.解决

很头痛,对于spring boot的依赖。看上面报错日志,按道理应该是包重复了,我看了下maven的依赖树,没发现重复的,上次碰到这种情况是tomcat包依赖重复,感觉这次也是,因为按道理spring boot web里面有tomcat,感觉这次也是这种情况,然后我将如下依赖注释

org.springframework.boot

spring-boot-starter-tomcat

provided

还是同样错误,网上搜到同样情况

有人说将provided注释即可,试了下果然可以,很奇怪,然后搜了下 maven 中的用法。

2.拓展

scope英文中的意思是范围,从使用规则上看,也符合这翻译, scope不同的值代表相应jar包不同的使用范围。

我们知道依赖一个jar分为以下四种使用环节

编译

运行

测试

打包

而它的值分为以下几种:

compile 。默认不填就是compile

compile

和前面解决办法将scope注释一样,注释不填默认就是如上compile。此种情况,这个jar参与如上所有环节

test

这个值经常用在测试相关的jar包上

org.springframework.boot

spring-boot-starter-test

test

runntime

此属性表示该jar不参与编译,但是运行、测试和打包都会参与

mysql

mysql-connector-java

runtime

provided

此属性表示除了最后该jar不打包到项目中,其他前面几个环节都参与。其实就和compile差不多,但是却被exclusion了。通过这应该可以找出开始报错的原因了,看配置

org.springframework.boot

spring-boot-starter

org.springframework.boot

spring-boot-starter-logging

org.springframework.boot

spring-boot-starter-tomcat

这里将spring boot里面自带的tomcat剔除了。然后又配置了

org.springframework.boot

spring-boot-starter-tomcat

provided

这里就很奇怪,因为spring-boot-starter里并没有tomcat,我们可以看看

为什么那里要exclusion,然后因为并没有依赖spring-boot-starter-web,所以其实这个工程是没有tomcat的,所以下面配置tomcat没啥毛病,但是可能provided并不参与打包,可能这里影响了整个项目的启动。

ok,虽然最后还有点疑问,但不影响问题解决。

No related posts.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值