1

I am learning Spring and I have a problem. I have created standalone application (web service) which run in embedded servlet container. I use Intellij IDEA with gradle. When I run application from IDEA - all work fine. But when I have created jar file and run via console ("java -jar my.jar") I have got error (below). I was load official sample (https://github.com/spring-guides/gs-rest-service) and it's not work too (via running jar). I see this link but it not helped me: Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

Please help

Error log:

18:47:26.079 [main] ERROR o.s.boot.SpringApplication - Application startup faile
d org.springframework.context.ApplicationContextException: Unable to start embedde
d container; nested exception is org.springframework.context.ApplicationContextE
xception: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedS
ervletContainerFactory bean.
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.onRefresh(EmbeddedWebApplicationContext.java:135) ~[ClientsIm.jar:na]
        at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:476) ~[ClientsIm.jar:na]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.refresh(EmbeddedWebApplicationContext.java:120) ~[ClientsIm.jar:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.
java:691) [ClientsIm.jar:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
:320) [ClientsIm.jar:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
:952) [ClientsIm.jar:na]
        at com.clientsim.server.Application.main(Application.java:13) [ClientsIm
.jar:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to st
art EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory
 bean.

My build.gradle:

group 'ClientsIm'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-release" }
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

sourceCompatibility = 1.5

repositories {
    maven { url "http://repo.spring.io/libs-release" }
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    testCompile group: 'junit', name: 'junit', version: '4.11'
}
1
  • What command are you running when you build your jar with Gradle? Commented Sep 12, 2016 at 20:49

1 Answer 1

0

Something tells me you did not create your jar using gradle ? Perhaps you exported it from intellij ?

(1) Build with gradle:

You should build your jar using gradle (to create the jar using spring-boot-gradle-plugin). Open a terminal at the root of your project and type:

$ gradle build
  ...

$ cd build/libs
$ java -jar yourjar.jar

(2) Export spring-boot jar from Intellij:

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! I have used gradle build and jar work fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.