IDEA启动Spring Boot项目提示Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServlet...
2017-05-10 13:41
1471 查看
导入一个
但是相应的Java代码没有报错,所以单独找了
找了很久都没有找到解决的方法,但是使用
看到有一篇使用
然后将
该问题产生的原因很可能是因为IDEA在启动的过程中并没有像
gradle的
Spring Boot项目,在启动的时候先提示找不到
HttpServletRequest这个包,错误如下:
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_45] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_45] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_45] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_45] ... 29 common frames omitted
但是相应的Java代码没有报错,所以单独找了
servlet-api.jar导入,并将其添加到
Module中,但是导入后出现另一个错误:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean. at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE] ....
找了很久都没有找到解决的方法,但是使用
gradle bootrun是可以正常启动运行的,在另外一台机子上也没有任何问题,所以认为项目本身没有任何问题,是在IDEA启动的过程中出现了问题导致的,
看到有一篇使用
Maven也遇到该问题的帖子,对比了依赖:
dependencies { compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.2.0') compile('org.springframework.boot:spring-boot-starter-web') runtime('mysql:mysql-connector-java') testCompile('org.springframework.boot:spring-boot-starter-test') // this is for generate war file providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') }
然后将
providedRuntime改成了
runtime,重新
build启动,没有任何问题
该问题产生的原因很可能是因为IDEA在启动的过程中并没有像
Gradle一样做完全的
build,只是进行了热更新,没有将需要的Jar包编译到项目里
providedCompile和
providedRuntime。虽然它们有各自的
compile和
runtime配置,但这些配置有相同的作用域,只是它们不会添加到
war/jar文件中。
相关文章推荐
- 从eclipse中导入到IDEA中的SpringBoot项目,启动时报错 Unable to start EmbeddedWebApplicationContext due to missing Em
- IDEA启动spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
- IDEA执行spring boot 出现Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
- Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFa
- Idea 启动Sringboot 报错 Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCont
- SpringbootUnable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFact
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- Spring Cloud | Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainer
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon
- 【Spring Cloud】Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletCon