Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.

最近开始使用idea,上来就这么一个错误。搜索总结如下:

我的依赖是这样的:

 

 


provided 依赖只有在当JDK 或者一个容器已提供该依赖之后才使用。例如, 如果你开发了一个web 应用,你可能在编译

classpath 中需要可用的Servlet API 来编译一个servlet,但是你不会想要在打包好的WAR 中包含这个Servlet API;这个

Servlet API JAR 由你的应用服务器或者servlet 容器提供。已提供范围的依赖在编译classpath (不是运行时)可用。它们

不是传递性的,也不会被打包。


在 Intellij Idea 15 中使用maven时,所有 scope 为 provided 的依赖都是不会被加入到 classpath 中的,目前该bug尚未被修复(bug report)。如果你的web应用是部署到容器中的,那么这个bug不会影响使用,因为web应用中provided的依赖在容器运行时会被提供。如果你做Spring Boot开发,有带provided的依赖时,直接在IDE中运行项目会导致ClassNotFound异常。解决方案有二:

    使用spring-boot:run这个 maven goal 运行程序。但这样会失去 Idea 的 debug功能,不推荐。
    点击IDE右侧的Maven Projects, 找到spring-boot:run,右键选择 debug 运行,如图:

 

posted on 2021-03-27 16:11  锋齐叶落  阅读(393)  评论(0编辑  收藏  举报