应用程序通过 Spring Boot Run 运行,但不通过 IntelliJ Idea 运行

Viv*_*han 2 intellij-idea maven spring-boot

我面临的问题是,当我通过命令行运行 Spring Boot 应用程序时

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev -Dserver.port=8083"
Run Code Online (Sandbox Code Playgroud)

这工作正常,但在 intellij 中作为应用程序运行时出现以下错误 -


Application run failed,
exc.stack=org.springframework.context.ApplicationContextException: 
Unable to start web server; nested exception is org.springframework.context.ApplicationContextException:

Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
Run Code Online (Sandbox Code Playgroud)

可能的原因是什么?我应该在哪里查找配置修复?

关于此模式还有其他问题,但没有一个提到错误 -

Spring Boot 应用程序通过 Maven 运行良好,但不能通过 IDE Intellij IDEA 运行良好

ApplicationContextException:由于缺少 ServletWebServerFactory bean,无法启动 ServletWebServerApplicationContext (对于缺少 servlet bean,但如果是这种情况,那么应用程序也不应该通过命令行启动)

所以,我在那里找不到任何答案。

小智 8

当您将 Tomcat 的依赖范围设置为“提供”时,可能会发生此错误,但在运行应用程序时,您没有选择“包含具有提供范围的依赖项”选项。

您可以在应用程序的运行配置下选择该选项。

在某些旧版本的 IntelliJ 中,您可能会看到一个复选框来启用相同的功能。

运行配置 IntelliJ 中的选项