Vivek Vardhan
Vivek Vardhan

Reputation: 1178

Application Running via Spring Boot Run but not via IntelliJ Idea

I am facing the issue where when I am running my spring boot application via Command line

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

This works fine, but running as Application in intellij I am getting below errors -


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)

What can be the possible reasons, and where should I look into configurations fixes?

There are other questions on this pattern, but none of them have mentioned the error -

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

ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean (For missing servlet bean, but if this is the case, then app should not have started via command line too)

So, I could not find any answer there.

Upvotes: 5

Views: 3128

Answers (2)

Prajval Singh
Prajval Singh

Reputation: 1151

Adding to the answer provided by @Ankit Raj, in the IntelliJ Idea 2022.3.1.

The option here is Add dependencies with "provided" scope to classpath

As shown in the

Screen shot of the

Upvotes: 2

Ankit Raj
Ankit Raj

Reputation: 256

This error could occur when you have Tomcat's dependency scope as "provided", but while running the application, you are not choosing the option "Include dependencies with provided scope".

You could select that option under the Run Configuration for your app.

In some older versions of IntelliJ, you might see a checkbox to enable the same.

Options in Run Configuration IntelliJ

Upvotes: 11

Related Questions