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.
總結
以上是生活随笔為你收集整理的mysql scope runtime_Maven依赖scope属性详解-一个报错引发的问题 - 老郭种树的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 初识python评课稿_开平方函数 py
- 下一篇: postgresql 遍历参数_Post