IDEA中scope 为 provided的问题

下面是启动异常:

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@30e868be: startup date [Thu Jan 18 15:06:45 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@79b06cab
	at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404) [spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578) [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554) [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961) [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523) [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968) [spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033) [spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555) [spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at com.suning.dasp.Application.main(Application.java:14) [classes/:na]

2018-01-18 15:06:45.713 ERROR 31312 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.eureka.server.EurekaServerInitializerConfiguration
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:579) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:279) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:230) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:570) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:279) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:230) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:197) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:166) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
	at com.suning.dasp.Application.main(Application.java:14) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.cloud.netflix.eureka.server.EurekaServerInitializerConfiguration
	at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:360) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:294) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:230) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:570) ~[spring-context-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	... 19 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
	at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_31]
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2693) ~[na:1.8.0_31]
	at java.lang.Class.getDeclaredMethods(Class.java:1967) ~[na:1.8.0_31]
	at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152) ~[spring-core-4.3.6.RELEASE.jar:4.3.6.RELEASE]
	... 23 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
	at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_31]
	at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_31]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_31]
	at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_31]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_31]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.8.0_31]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_31]
	... 27 common frames omitted

IDEA版本:

查了一部分资料,根本原因如下:

在 Intellij Idea  中使用maven时,所有 scope 为 provided 的依赖都是不会被加入到 classpath 中的,目前该bug尚未被修复。如果你做Spring Boot开发,有带provided的依赖时,直接在IDE中运行项目会导致ClassNotFound异常。

自行查看未修复bug,传送门 —— https://youtrack.jetbrains.com/issue/IDEA-107048

解决方案简单粗暴,找到pom.xml中的如下依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-tomcat</artifactId>
	<!--<scope>provided</scope>-->
</dependency>

将对应的scope 注释掉即可。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏AI科技大本营的专栏

AI一分钟|美团确认收购摩拜;特斯拉今年第一季度产量创历史新高

整理 | 明明 一分钟AI 1、Facebook 又双叒叕出来道歉了:因保存用户已删除视频 2、OPPO 与斯坦福大学建立联合实验室,共同落地 AI 技术应...

3106
来自专栏高性能服务器开发

工作后的成长速度是如何产生差异的?

不要因为钱跳槽,为个人能力和背书增值而跳槽 当你面临选择时 平台,待遇,个人成长与空间,团队,行业 你更看重什么? 一定没有十全十美的选择 赋权排序吧...

2717
来自专栏量子位

附议库克!AWS CEO也要求彭博撤回涉及中国芯片的报道

这就是苹果、亚马逊和服务器厂商超微(Super Micro)等公司目前最真实的写照。

481
来自专栏FreeBuf

IT专业人士与政策制定者:如何才能跨过交流鸿沟

IT专业人人士和政策制定者都十分关注网络安全,但是他们似乎没有太多的共同语言,有时甚至是对立的,现在让我们了解在美国,这些网络安全专家是如何找到共同的驻足点的。...

2987
来自专栏专知

全球100大科技领导企业榜单出炉,美国数量居冠

近日,汤森路透 (Thomson Reuters) 发表首份 “全球百大科技领导企业”名单 (The Top 100 Global Technology Lea...

3395
来自专栏机器学习算法与Python学习

科技部公布2017年创新人才推进计划入选名单,有认识的吗?

各省、自治区、直辖市及计划单列市科技厅(委、局),新疆生产建设兵团科技局,国务院各有关部门、直属机构,中央军委政治工作部干部局,各有关单位:

1314
来自专栏量子位

中兴大结局!14亿美元交出去,旧管理层被血洗,股价直拉涨停

1063
来自专栏新智元

【AI 引擎】谷歌联想推新设备 | 通用汽车Lyft开发无人车

1.Google联想将在CES上推出Project Tango设备 ? 据外媒报道,Google在2014年推出了Project Tango,该项目旨在为智能手...

3087
来自专栏高性能服务器开发

职场里的哪些问题,是在你经历了第一次跳槽之后才想通了的?

不要因为钱跳槽,为个人能力和背书增值而跳槽 当你面临选择时 平台,待遇,个人成长与空间,团队,行业 你更看重什么? 一定没有十全十美的选择 赋权排序吧...

3437
来自专栏AI科技大本营的专栏

AI一分钟|AI聊机器人“Shibuyu Mirai”获日本居住权,传今日头条3亿美元收购Faceu激萌

一分钟AI 继Sophia获得公民权后,AI聊机器人“Shibuyu Mirai”获日本居住权 今日头条收购相机拍照工具Faceu激萌,据传交易总价约为3亿...

3245

扫码关注云+社区