简体   繁体   English

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

[英]Unable to start spring-boot application in IntelliJ Idea

Overview 概观

I can run the application by using maven plugin of spring-boot but not run it with the IDE. 我可以使用spring-boot的maven插件运行应用程序,但不能使用IDE运行它。 The following lines give some detail about my program. 以下几行详细介绍了我的程序。

The application class is as follows: 应用程序类如下:

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);
    }
}

The exception stack trace is as follows: 异常堆栈跟踪如下:

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.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

I used @SpringbootApplication but to no avail. 我使用@SpringbootApplication但无济于事。

Question

So I would appreciate it if anyone could help me solve this issue. 如果有人能帮我解决这个问题,我将不胜感激。

I am guessing you have a war packaging project with Maven and you've flagged your servlet engine (tomcat) as provided. 我猜你有一个与Maven的war包装项目,你已经标记了你提供的servlet引擎(tomcat)。

Unfortunately, IntellIJ IDEA does not add provided dependencies in the runtime classpath , that's why your project does not work when you run it from the IDE. 遗憾的是,IntellIJ IDEA不会在运行时类路径中添加provided依赖项 ,这就是当您从IDE运行它时项目不起作用的原因。

UPDATE 7/30/2019 更新7/30/2019

As per Giorgio: 根据Giorgio的说法:

They have added a checkbox in the Application Run Configuration to "Include dependencies with 'Provided' scope" 他们在“应用程序运行配置”中添加了一个复选框,以“包含具有'提供'范围的依赖项”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM