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'
}
Something tells me you did not create your jar using gradle ? Perhaps you exported it from intellij ?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.