16

Overview

I can run the application by using maven plugin of spring-boot but not run it with the 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.

Question

So I would appreciate it if anyone could help me solve this issue.

saeedj
  • 2,179
  • 9
  • 25
  • 38

1 Answers1

28

I am guessing you have a war packaging project with Maven and you've flagged your servlet engine (tomcat) as provided.

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.

UPDATE 7/30/2019

As per Giorgio:

They have added a checkbox in the Application Run Configuration to "Include dependencies with 'Provided' scope"

GSerjo
  • 4,725
  • 1
  • 36
  • 55
Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89
  • 4
    Thank you so much. That was exactly my problem. I changed "spring-boot-starter-tomcat" dependency scope to compile and it was run properly. – saeedj Aug 21 '16 at 22:38
  • 9
    They have added a checkbox in the Application Run Configuration to "Include dependencies with 'Provided' scope" – Oskar Apr 19 '18 at 06:49
  • @Giorgio can you tell me in which version of IntelliJ you see the option? – Ena Apr 20 '18 at 08:08
  • @Ena I am using: IntelliJ IDEA 2018.1.1 (Community Edition) Build #IC-181.4445.78, built on April 10, 2018 JRE: 1.8.0_152-release-1136-b27 x86_64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o macOS 10.13.4 – Oskar Apr 23 '18 at 05:09
  • Thank you this also solved my problem on Ubuntu 20.04, IntelliJ IDEA 2020.2 EAP (Community Edition) Build #IC-202.5792.28, built on June 18, 2020 Runtime version: 11.0.7+10-b944.12 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.4.0-37-generic GC: ParNew, ConcurrentMarkSweep Memory: 725M Cores: 8 Non-Bundled Plugins: com.intellij.plugins.watcher Current Desktop: ubuntu:GNOME – serdarsen Jun 21 '20 at 08:49
  • Thanks solved my problem in Windows 21H1 and IntelliJ build 2021.2.3 (CE) & OpenJDK 64-Bit Server VM Temurin-11.0.12+7 – Jankiel Goldman Nov 19 '21 at 14:12
  • Thank you so much., It solved my problem, Had a confusion why my code runs in STS and fails in Intellij IDEA – Vignesh Ravichandran Aug 03 '22 at 15:29