【问题标题】:Application Running via Spring Boot Run but not via IntelliJ Idea通过 Spring Boot Run 但不是通过 IntelliJ Idea 运行的应用程序
【发布时间】:2021-12-11 10:43:35
【问题描述】:

当我通过命令行运行我的 Spring Boot 应用程序时,我遇到了这个问题

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev -Dserver.port=8083"

这工作正常,但在 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)

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

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

Spring Boot application runs fine via Maven but not via IDE Intellij IDEA

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

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

【问题讨论】:

标签: spring-boot maven intellij-idea


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 1970-01-01
    • 2016-03-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    相关资源
    最近更新 更多