当前位置: 首页 > 面试题库 >

无法在IntelliJ Idea中启动spring-boot应用程序

昌乐
2023-03-14
问题内容

总览

我可以使用spring-boot的maven插件运行该应用程序,但不能在IDE中运行它。以下几行提供有关我的程序的一些详细信息。

应用程序类如下:

package com.blss.retailServices.dataExportRouter;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.velocity.VelocityAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan
@EnableAutoConfiguration(exclude = { VelocityAutoConfiguration.class })
public class DataExportRouterApplication {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(DataExportRouterApplication.class, args);
    }
}

异常堆栈跟踪如下:

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:133) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at com.blss.retailServices.dataExportRouter.DataExportRouterApplication.main(DataExportRouterApplication.java:14) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_74]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.html" target="_blank">java:62) ~[na:1.8.0_74]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_74]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_74]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:185) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:158) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
    ... 13 common frames omitted

我使用@SpringbootApplication但无济于事。

因此,如果有人可以帮助我解决此问题,我将不胜感激。


问题答案:

我猜想您有一个war与Maven一起打包的项目,并且已标记了所提供的servlet引擎(tomcat)。

不幸的是,IntellIJIDEA并未在运行时类路径中添加provided依赖项,这就是为什么从IDE运行项目时项目无法工作的原因。

更新7/30/2019

根据Giorgio:

他们在“应用程序运行配置”中添加了一个复选框,以“包括具有“已提供”作用域的依赖项”



 类似资料:
  • 所以如果有人能帮我解决这个问题,我将不胜感激。

  • 问题内容: 我有一个使用Spring Boot Actuator的Java后端,但不会在Digitalocean Ubuntu VPS上启动。同一应用程序可以在我的Mac和另一台Ubuntu PC上很好地运行。 它开始初始化,但每次都在同一点停止(无例外,只是挂起)。如果我尝试在此时停止它,它将不会带回外壳。 这是输出: 这是在:之后的输出 有人遇到过同样的问题吗?你们能帮我吗? 这里有线程转储(

  • 我试图用嵌入式tomcat运行一个web应用程序,包括许多spring批处理作业和spring批处理管理。然而,当我试图运行生成的fat jar时,我得到了以下错误,spring batch或boot团队的任何人都可以帮忙吗: 添加更多信息:spring Boot版本:1.1.9。从spring.io父pom版本1.0.3发布。版本我尝试从STS以及使用mvn spring-boot:run运行它

  • 我开发了一个Spring启动应用程序,它使用JMS在Activemq中发送和监听消息,但在运行应用程序时,JMS无法在Spring启动时启动 这里是主舱Application.java 配置类:Config.java 侦听器类用于侦听队列:Listener.java Producer类用于从控制器Producer.java向队列发送消息 application.properties pom.xml

  • 我试图在Intellij Idea中运行应用程序,但我遇到了以下错误。。。。 org.springframework.beans.factory.BeanCreationException:创建名为'globalExceptionHandler'的bean时出错:查找方法解析失败;嵌套异常java.lang.IllegalStateException:无法自省类[com.app.exception

  • 我正在尝试转换由spring boot应用程序到spring原生使用本机图像Maven插件。我按照这里提到的https://docs.spring.io/spring-native/docs/0.9.x/reference/htmlsingle/设置GraalVM和本机映像 本机映像打包成功。但应用程序无法以erorr启动 spring原生版本:0.9.0 spring boot版本:2.4.3

  • 想要基于spring boot starter mail实现简单邮件发送器解决方案在添加依赖项并设置属性后,我试图运行应用程序,但出现了错误。我认为值得注意的是,我没有,也不打算实现Spring Cloud。只有邮件服务。不明白为什么spring boot需要来自这些包的一些服务。 尝试了不同版本的依赖关系,定义了一些@Beans,但不认为这是问题所在 日志: 只想通过smtp发送电子邮件。gma